BrutalDawg
New Member
- Joined
- Jun 10, 2015
- Messages
- 41
I have a macro that loops through sheet2 column A and if found on sheet1 column A copies to next row on sheet3. The code works well, but I am coming across new sheets, where the code will need to search sheet1 in different columns, ie g,c,h etc. I can just edit the code each time but others are unable to understand. Is there a way when the you run the macro, a dialog box can pop up asking which row to search and automatically change the code? Below is the macro im currently using.
Code:
Option ExplicitSub Find_Sort_EDI()
Dim srchLen, myString, nxtRw As Integer
Dim firstAddress As String
Dim c As Range
'Clear Sheet 3 and Copt Column Headings from Sheet 1
Sheets(3).Cells.ClearContents
Sheets(1).Rows(1).Copy Destination:=Sheets(3).Rows(1)
'Determine length of Search Criteria Column from Sheet2
srchLen = Sheets (2).Range("A" & Rows.Count).EndxlUp).Row
'Loop through list in Sheet2, Column A. As each value is
'found in Sheet1, Column A, copy it to the next row in Sheet3
With Sheets(1).Columns(A")
For myString = 2 To srchLen
Set c = .Find(Sheets(2).Range("A" & myString), lookat=xlWhole)
If Not c Is Nothing Then
firstAdress = c.Address
Do
nxtRw = Sheets(3).Range("A" & Rows.Count).End(xlUp).Row + 1
c.EntireRow.Copy Destination :=Sheets(3).Range("A' & nxtRw)
Set c = .FindNext(c)
Loop While Not C Is Nothing And c.Address <> firstAddress
End If
Next
End With
End Sub