Create a set of related formulas in a column: use a looping structure to iterate through the cells that receive the formula : Formula « Excel « VBA / Excel / Access / Word






Create a set of related formulas in a column: use a looping structure to iterate through the cells that receive the formula

 
Sub formula()
    Dim formulaString As String
    Dim I As Integer
    Cells(1, "B").Value = Cells(1, "A").Value
    For I = 2 To 10
    formulaString = "=A" & Trim(str(I)) & "+B" & Trim(str(I - 1))
    Cells(I, "B").formula = formulaString
    Next I
End Sub

 








Related examples in the same category

1.Fill formula to cell
2.Inserts a formula in cell A11 of a worksheet that calculates the sum of the values in the range A2:A10 using the Excel application's SUM function
3.Use [] to evaluate formula
4.Is active cell empty
5.Two ways you can use Evaluate to generate a reference to a Range object, and assign a value to that object
6.The Evaluate method can also be used with arrays.
7.Assigns the values 101 to 200 to the range B1:B100, and again does it more efficiently than a For...Next loop
8.Use Copy and Paste or AutoFill functions