I have this worksheet that I have an IF formula in VBA that searches V9:Z9 for like values (DIST8 and DIST6). The formula fills AO9 with a 1 or 0. This formula works for my purpose.
I want to repeat this formula until the last row.
Dim DIST8 As String
Dim DIST6 As String
DIST8 = "DIST8"
' Select cell A9, *first line of data*.
Range("A9").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here
If Worksheets("Sheet1").Range("v9") Like "*" & "DIST8" & "*" Or Worksheets("Sheet1").Range("w9") Like "*" & "DIST8" & "*" Or Worksheets("Sheet1").Range("x9") Like "*" & "DIST8" & "*" Or Worksheets("Sheet1").Range("y9") Like "*" & "DIST8" & "*" Or Worksheets("Sheet1").Range("z9") Like "*" & "DIST8" & "*" Or Worksheets("Sheet1").Range("v9") Like "*" & "DIST6" & "*" Or Worksheets("Sheet1").Range("w9") Like "*" & "DIST6" & "*" Or Worksheets("Sheet1").Range("x9") Like "*" & "DIST6" & "*" Or Worksheets("Sheet1").Range("y9") Like "*" & "DIST6" & "*" Or Worksheets("Sheet1").Range("z9") Like "*" & "DIST6" & "*" Then
Worksheets("Sheet1").Range("Ao9").Value = 1
Else
Worksheets("Sheet1").Range("Ao9").Value = 0
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
Unfortunately the loop isn't working correctly, the sheet will scroll down to the last row but not filling the IF beyond the first row. I want to run the same IF formula but change the row number eg; v9 to v10, w9 to w10, etc.
What is the best way of achieving this?
Aucun commentaire:
Enregistrer un commentaire