I have a master price list for ordering stock and the following code works as long as I'm always ordering from all suppliers.
I filter out the all items which are being ordered when quantity required column is greater than zero (field 11 > 0)
Then I filter by supplier column (field 2) and copy any visible cells over to the order form for that supplier.
All is good until I don't order anything from 1 of the suppliers and code stalls. There are no visible cells to copy and paste therefore
it spits the dummy.
Here is my code:
I probably need an If/Then scenario?
I filter out the all items which are being ordered when quantity required column is greater than zero (field 11 > 0)
Then I filter by supplier column (field 2) and copy any visible cells over to the order form for that supplier.
All is good until I don't order anything from 1 of the suppliers and code stalls. There are no visible cells to copy and paste therefore
it spits the dummy.
Here is my code:
Code:
Sub filterorderstoeachsupplier()
'
' filterorderstoeachsupplier Macro
'
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A2").Select
Selection.AutoFilter
ActiveSheet.Range("$A$2:$P$5000").AutoFilter Field:=11, Criteria1:=">0", Operator:=xlAnd
ActiveSheet.Range("$A$2:$P$5000").AutoFilter Field:=2, Criteria1:="lumberyard"
Range("A3:M" & LR).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("lumberyard").Select
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Sheets("price list master copy").Select
ActiveSheet.Range("$A$2:$P$5000").AutoFilter Field:=2, Criteria1:="paintshop"
'in here need something like "If Nothing Visible Then Don't Do The Next Bit"
'code crashes at this line
Range("A3:M" & LR).SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("paintshop").Select
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
'End If
Sheets("price list master copy").Select
'Selection.AutoFilter
End Sub