Pasting cell contents into a macro

Joined
Aug 21, 2018
Messages
1
Reaction score
1
Hi,

Newbie to Macros

Essentially I'm trying to run a macro in which I can select a word from a drop down list but unfortunately when I record the macro..the cell copies as a value and therefore I can't re-run the macro?

Sub master()
'
' master Macro
'

'
Activecell.select
Selection.Copy
Sheets("Data").Select
ActiveSheet.Range("$A$1:$N$6546").AutoFilter Field:=3, Criteria1:= _
"Apples"
End Sub

I'm trying to do it so instead of "Apples" it comes up with whatever is in the active cell.

Any help appreciated!
 
This doc says that when you use the Copy method without a destination argument that it copies to the clipboard: https://docs.microsoft.com/en-us/office/vba/api/excel.range.copy

Now that you've copied to the clipboard you have to paste from that. You would be better off storing the selection into a string variable and then use that as part of your AutoFilter call.

Dim selvalue As String = Selection.Text
ActiveSheet.Range("").AutoFilter Criteria1:=selvalue

I didn't write all of the code you need but you get the idea. I hope this helps :user:
 
Back
Top