Hi,
I'm trying to use the following code to insert that formula into a range of cells (F:Q) of the rows where "Total" appears on column D. I'm only verifying if "Total" is on column D from row 8 to the last row containing data, which I get using the function LastRowIndex. I'm running excel 2011 for MAC.
I can't find the problem. It might be the way I am specifying the range. Any help will be much appreciated!
Thanks!
The LastRowIndex function and this formula were tested and are working properly:
=SUM(INDIRECT(CHAR(COLUMN()+64)&ROW()-INDIRECT("C"&ROW())):INDIRECT(CHAR(COLUMN()+64)&ROW()-1))
This is the VBA code (not working):
Sub Totals()
Dim lines, NumRow As Integer
lines = LastRowIndex(ActiveSheet, 4)
NumRow = 8
While NumRow <= lines
If Cells(NumRow, 4) = "Total" Then
Range("F" & NumRow & ":Q" & NumRow).Formula = "=SUM(INDIRECT(CHAR(COLUMN()+64)&ROW()-INDIRECT(""C""&ROW())):INDIRECT(CHAR(COLUMN()+64)&ROW()-1))"
Else
NumRow = NumRow + 1
End If
Wend
I'm trying to use the following code to insert that formula into a range of cells (F:Q) of the rows where "Total" appears on column D. I'm only verifying if "Total" is on column D from row 8 to the last row containing data, which I get using the function LastRowIndex. I'm running excel 2011 for MAC.
I can't find the problem. It might be the way I am specifying the range. Any help will be much appreciated!
Thanks!
The LastRowIndex function and this formula were tested and are working properly:
=SUM(INDIRECT(CHAR(COLUMN()+64)&ROW()-INDIRECT("C"&ROW())):INDIRECT(CHAR(COLUMN()+64)&ROW()-1))
This is the VBA code (not working):
Sub Totals()
Dim lines, NumRow As Integer
lines = LastRowIndex(ActiveSheet, 4)
NumRow = 8
While NumRow <= lines
If Cells(NumRow, 4) = "Total" Then
Range("F" & NumRow & ":Q" & NumRow).Formula = "=SUM(INDIRECT(CHAR(COLUMN()+64)&ROW()-INDIRECT(""C""&ROW())):INDIRECT(CHAR(COLUMN()+64)&ROW()-1))"
Else
NumRow = NumRow + 1
End If
Wend