cjvenables
Board Regular
- Joined
- Aug 2, 2011
- Messages
- 65
Can someone help me finish this?
This macro searches through 12 tabs (January SAP, February SAP, etc). When it finds the vendor number listed below, it copies the whole row and pastes it to a whole sheet. The problem is that it only returns 1 row for each month. I know for certain that this vendor has roughly 4K results, so I need this macro to find all results and paste them onto a new sheet. 12 separate tabs>1 consolidated tab.
I have found macros that returns all rows in one tab, but finding one that returns all rows across all tabs has been elusive. Sounds more like an IF statement than a FIND?
I'm almost there and need your help!
Also, if I wanted this to return multiple vendors, how could I have it search by multiple numbers?
Thanks!
Sub Copy_Vendor_Rows()
Dim i As Integer, Nextrow As Long
Dim FindVend As Range, Vendor As Variant
Dim wsDest As Worksheet
Set wsDest = Sheets("Sheet2") 'Destination worksheet
Nextrow = 1 'starting row on destination worksheet
Vendor = 12345 'Find vendor number
For i = 1 To 12
With Sheets(MonthName(i) & " SAP")
Set FindVend = .Range("H:H").Find(Vendor, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FindVend Is Nothing Then
FindVend.EntireRow.Copy _
Destination:=wsDest.Rows(Nextrow)
Nextrow = Nextrow + 1
End If
End With
Next i
End Sub
_________________
This macro searches through 12 tabs (January SAP, February SAP, etc). When it finds the vendor number listed below, it copies the whole row and pastes it to a whole sheet. The problem is that it only returns 1 row for each month. I know for certain that this vendor has roughly 4K results, so I need this macro to find all results and paste them onto a new sheet. 12 separate tabs>1 consolidated tab.
I have found macros that returns all rows in one tab, but finding one that returns all rows across all tabs has been elusive. Sounds more like an IF statement than a FIND?
I'm almost there and need your help!
Also, if I wanted this to return multiple vendors, how could I have it search by multiple numbers?
Thanks!
Sub Copy_Vendor_Rows()
Dim i As Integer, Nextrow As Long
Dim FindVend As Range, Vendor As Variant
Dim wsDest As Worksheet
Set wsDest = Sheets("Sheet2") 'Destination worksheet
Nextrow = 1 'starting row on destination worksheet
Vendor = 12345 'Find vendor number
For i = 1 To 12
With Sheets(MonthName(i) & " SAP")
Set FindVend = .Range("H:H").Find(Vendor, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FindVend Is Nothing Then
FindVend.EntireRow.Copy _
Destination:=wsDest.Rows(Nextrow)
Nextrow = Nextrow + 1
End If
End With
Next i
End Sub
_________________