Hello,
I'm looping with VBA through a range (2 columns) and need to perform 4 different actions. In column O, row 2 (the 1st cell) I have action A, in the last cell, action C, and in the cells in between action B. In the second column, I perform Action D for the whole range. The # of rows is the same in both columns.
I'd like to know if I can use only 1 single loop counter k, or if I should define more, say 3 counter variables per action, or 2 counter variables per column? Here is the example:
I'm looping with VBA through a range (2 columns) and need to perform 4 different actions. In column O, row 2 (the 1st cell) I have action A, in the last cell, action C, and in the cells in between action B. In the second column, I perform Action D for the whole range. The # of rows is the same in both columns.
I'd like to know if I can use only 1 single loop counter k, or if I should define more, say 3 counter variables per action, or 2 counter variables per column? Here is the example:
Code:
'Column O
k = Range("M" & Rows.coUnt).End(xlUp).Row
'** first cell of range
Range("O2").FormulaR1C1 = Action A
'**cells in between
For k = 3 To k - 1
Range("O" & k).FormulaR1C1 = Action B
Next k
'** last cell of range
Range("O" & k).FormulaR1C1 = Action C
'Column P
Cells(k, "P").FormulaR1C1 = Action D
Last edited: