TheBaron26
New Member
- Joined
- Mar 15, 2011
- Messages
- 17
Hi,
I'm fairly new to VBA and am looking to write some code to autofill a formula.
I have the following code which works for column "I", but need to expand it to loop round until it finds the last column with data, offsetting by 2 columns each time (so start at column I, row 2, then column K, row 2, then column m, row 2 etc).
Hope this makes sense and any pointers would be greatly appreciated!
regards
R
I'm fairly new to VBA and am looking to write some code to autofill a formula.
I have the following code which works for column "I", but need to expand it to loop round until it finds the last column with data, offsetting by 2 columns each time (so start at column I, row 2, then column K, row 2, then column m, row 2 etc).
Code:
Sub Autofill()
Dim LastRow As Long, j As Long
With Sheets("Data Dump")
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]<>"""",R1C[-1]<=TODAY()),RC[-1]-RC[-3],"""")"
Range("I2").Select
Range("I2").Autofill Destination:=Range("I2:I" & LastRow)
End With
End Sub
Hope this makes sense and any pointers would be greatly appreciated!
regards
R