Below is my attempt at a loop macro, it seems to be working fine and then after 2 loops it stops!
It shouldn't stop until it finds the "ProductName" cell to be blank.
Can anyone see something i am doing wrong?
I have also got it running all the way through by removing the line in red, but it only stops because of an error......
Using this method what is the best way for me to stop the macro?
---------------------------------------------------------------
Dim ProductParts
Dim ProductName
Dim ProductRange
Dim KeepSearching
ProductParts = -1
ProductName = -1
ProductRange = -1
KeepSearching = True
Do While KeepSearching
If ProductName = Empty Then
KeepSearching = False
End If
ProductParts = ProductParts + 1
ProductName = ProductName + 1
ProductRange = ProductRange + 1
If Range("A2").Offset(0, ProductName) <> Empty Then
Sheets("P1").Select
Range("A4").Select
ActiveCell.Offset(0, ProductParts).Select
Sheets("family_attach_rate").Select
ActiveSheet.Range("$A$1:$G$282").AutoFilter Field:=2, Criteria1:=Sheets("P1").Range("A2").Offset(0, ProductName), Operator:=xlOr, Criteria2:=Sheets("P1").Range("A1")
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("P1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("A4").Select
ActiveCell.Offset(0, ProductRange).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.RemoveDuplicates Columns:=1, Header:=xlYes
End If
Loop
End Sub
It shouldn't stop until it finds the "ProductName" cell to be blank.
Can anyone see something i am doing wrong?
I have also got it running all the way through by removing the line in red, but it only stops because of an error......
Using this method what is the best way for me to stop the macro?
---------------------------------------------------------------
Dim ProductParts
Dim ProductName
Dim ProductRange
Dim KeepSearching
ProductParts = -1
ProductName = -1
ProductRange = -1
KeepSearching = True
Do While KeepSearching
If ProductName = Empty Then
KeepSearching = False
End If
ProductParts = ProductParts + 1
ProductName = ProductName + 1
ProductRange = ProductRange + 1
If Range("A2").Offset(0, ProductName) <> Empty Then
Sheets("P1").Select
Range("A4").Select
ActiveCell.Offset(0, ProductParts).Select
Sheets("family_attach_rate").Select
ActiveSheet.Range("$A$1:$G$282").AutoFilter Field:=2, Criteria1:=Sheets("P1").Range("A2").Offset(0, ProductName), Operator:=xlOr, Criteria2:=Sheets("P1").Range("A1")
Range("C2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("P1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Range("A4").Select
ActiveCell.Offset(0, ProductRange).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.RemoveDuplicates Columns:=1, Header:=xlYes
End If
Loop
End Sub