Home » excel » vba – Apply formula to every other column in excel

vba – Apply formula to every other column in excel

Posted by: admin May 14, 2020 Leave a comment

Questions:
Sub Repeat()
Range("F3").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'ASLs total'!C[-5]:C[-4],2,0)"
Range("F3").Select
Selection.AutoFill Destination:=Range("F3:F1159")
Range("F3:F1159").Select
End Sub

I want to apply this formula to the D, F, H, …. all the way downa bout 500 columns, every other column.

Any idea on how to do this?

How to&Answers:

You could accomplish this via a for loop using the step function. Something like this:

Sub Repeat()
    For ColNum = 4 To 500 Step 2
        Range(Cells(3, ColNum), Cells(1159, ColNum)).FormulaR1C1 = "=VLOOKUP(RC[-1],'ASLs total'!C[-5]:C[-4],2,0)"
    Next ColNum
End Sub

Hope this helps