chrono2483
Board Regular
- Joined
- Aug 23, 2014
- Messages
- 164
- Office Version
- 2016
Hello,
I have a spreadsheet, where I'm trying to use a Button to run a macro. There are two tabs in this workbook: Sheet 1 (where the raw data is) and Sheet 2 (where I want to pull data from Sheet 1 to display).
What I want the button to do is reference Sheet 1, and search Column C for all occurrences on the word "Name", copy it and Paste it in Column AA on the same Sheet 1.
The below code is what I'm using (taken from a different tool, where it works), but I get the error "Compile Error Variable Not Defined", and highlights the "Set SrchRng", just below 'Sheets("Sheet1").Select'. Would anyone know what I could be doing wrong?
Thanks!
I have a spreadsheet, where I'm trying to use a Button to run a macro. There are two tabs in this workbook: Sheet 1 (where the raw data is) and Sheet 2 (where I want to pull data from Sheet 1 to display).
What I want the button to do is reference Sheet 1, and search Column C for all occurrences on the word "Name", copy it and Paste it in Column AA on the same Sheet 1.
The below code is what I'm using (taken from a different tool, where it works), but I get the error "Compile Error Variable Not Defined", and highlights the "Set SrchRng", just below 'Sheets("Sheet1").Select'. Would anyone know what I could be doing wrong?
Code:
Sub Button1_Click()
'
' Button1_Click Macro
'
' Keyboard Shortcut: Ctrl+Shift+J
'
Dim i As Long
Sheets("Sheet1").Select
Set SrchRng = ActiveSheet.Range("C1", ActiveSheet.Range("C25000").End(xlUp))
Set myCell = SrchRng.Find("Name", LookIn:=xlValues)
If Not myCell Is Nothing Then
firstAddress = myCell.Address
i = 3
myCell.Copy Cells(i, "AA")
Else
MsgBox "Can't find search string"
Exit Sub
End If
Do
Set myCell = SrchRng.FindNext(myCell)
If myCell Is Nothing Then Exit Do
If myCell.Address = firstAddress Then Exit Do
i = i + 1
myCell.Copy Cells(i, "AA")
Loop
End Sub
Thanks!