I want to create a formula in excel and I am using the below code. It works however, if there is no data in the referenced cells so nothing gets computed until data is entered and the macro is run again. I want the macro to run in the begining and input the formulas in the designated cells so when the user updates the referenced cells it auto computes.
Also, is there a better way to sum up the second portion of the code? As of now I am rerfencing each cell indicidually.
If Cells(i, 8).Formula = "GROSS PROFIT. SUBTRACT LINE 2 FROM LINE 1." Then
Cells(i, 8).Font.Bold = True
j = 9
Do While Cells(1, j) <> ""
Cells(i, j).Formula = Cells(i - 2, j).Formula - Cells(i - 1, j)
j = j + 1
Loop
ElseIf Cells(i, 8).Formula = "TOTAL INCOME. ADD LINES 3 THROUGH 10." Then
Cells(i, 8).Font.Bold = True
j = 9
Do While Cells(1, j) <> ""
Cells(i, j).Formula = Cells(i - 7, j).Formula + Cells(i - 6, j) + Cells(i - 5, j) + Cells(i - 4, j) + Cells(i - 3, j) + Cells(i - 2, j) + Cells(i - 1, j)
j = j + 1
Loop
Bookmarks