You should look into arrays.
The code above could be done like this:
Dim i As Long
Dim myRange(1 To 3) As Range
For i = 1 To 3
Set myRange(i) = Cells(1, i)
Next i
Dim formulaString(1 To 3) As String
For i = 1 To 3
formulaString(i) = "=" & CStr(2 * i - 1) & "+" & CStr(2 * i)
Next i
For i = 1 To 3
myRange(i).FormulaR1C1 = formulaString(i)
Next i
This could be further simplified, to one loop
Dim myRange(1 To 3) As Range
Dim formulaString(1 To 3) As String
Dim i As Long
For i = 1 To 3
Set myRange(i) = Cells(1, i)
formulaString(i) = "=" & CStr(2 * i - 1) & "+" & CStr(2 * i)
myRange(i).Formula = formulaString(i)
Next i
Starting with arrays and using For..Next loops makes it easier to see this version.
Dim i As Long
For i = 1 to 3
Cells(1,i).FormulaR1C1 = "=" & CStr(2 * i - 1) & "+" & CStr(2*i)
Next i
Unless you need myRange or formulaString later in the routine, this would be the way to go.
Bookmarks