JosephALin
New Member
- Joined
- May 13, 2016
- Messages
- 13
Good morning, I am building a macro that will find a certain text from cell A2 sheet named Committees withing the range of P2:CP5000 in sheet called database, and return data of column A:O in the same rows from all the rows that contain this text string, and print it out on the sheet called reports. Here is what I have done, but it doesn't work, I couldn't figure out what is wrong. Please check for me.
Thanks in advance!
Code:
Sub Macro1()'
'
' Macro1 Macro
'
Dim r1 As Range, r2 As Range, r3 As Range
Dim rw1 As Long, LastRow As Long, i As Long
Set r2 = Sheets("Committees").Range("A2")
Set r1 = Sheets("Database").Range("P2:CO5000")
Set r3 = Sheets("Reports").Range("F2")
rw1 = r1.Find(What:=r2.Value, After:=r1(1)).Row
LastRow = Cells(r1.Rows, Count, "U").End(xlUp).Row
For i = 1 To LastRow
If Not rw1 Is Nothing Then
Do Until rw1 Is Nothing
Sheets("Database").Range("A" & rw1 & ":O" & rw1).Copy r3
Set rw1 = .FindNext(rw1)
Loop
End If
Set rw1 = Nothing
Next
End Sub
Thanks in advance!