Hi Team,
I am putting subtotal formula on once cell up on headers. there are 18 columns in Total.
by using loop my code will be shorter. I am using match function to find column headers.
thanks
mg
I am putting subtotal formula on once cell up on headers. there are 18 columns in Total.
by using loop my code will be shorter. I am using match function to find column headers.
VBA Code:
Sub Subtotal_Formula
Dim cInvoice as long
Dim cNotional as long
Dim lr_new as long
cInvoice = application.worksheetfunction.match("Invoice",range("a1:z1"),0)
cNotional = application.worksheetfunction.match("Invoice",range("a1:z1"),0)
lr_new = 2000
With ws_Master
.Cells(2,cInvoice).FormulaR1C1 = "=SUBTOTAL(9,R2C" & cInvoice & ":R" & lr_new & "C" & cInvoice & ")"
.Cells(2,cNotional).FormulaR1C1 = "=SUBTOTAL(9,R2C" & cNotional & ":R" & lr_new & "C" & cNotional & ")" and so on .......
end with
'------------convert above code [B]something [/B]like this------
Looking help in loop.
Dim AryColumn As Variant
AryColumn = Array(cInvoice,cNotional)
With ws_Master
For i = 0 To UBound(AryColumn)
.Cells(2, AryColumn(i)).FormulaR1C1 = "=SUBTOTAL(9,R2C" & AryColumn(i) & ":R" & lr_new & "C" & AryColumn(i) & ")"
.Cells(2, AryColumn(i)).FormulaR1C1 = "=SUBTOTAL(9,R2C" & AryColumn(i) & ":R" & lr_new & "C" & AryColumn(i) & ")"
Next i
End With
thanks
mg