I'm trying to build a macro to dynamically choose which columns to display a subtotal when using the subtotal function. It looks like it just uses an array for the list that's normally in the Subtotal Wizard. Here's the code I've attempted.
Sub Subtotal_Create()
Dim ARString As String
'Creates subtotals for sheet
ARString = "8,9,10,11,12"
For i = 13 To lastcol
ARString = ARString & "," & i
Next i
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(ARString), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
End Sub
I always want columns 8:12 but the rest may be shorter or longer depending on the data I'm importing. Is there a way to get that string into the command like I'm attempting or is there another, easier way to do it?
Sub Subtotal_Create()
Dim ARString As String
'Creates subtotals for sheet
ARString = "8,9,10,11,12"
For i = 13 To lastcol
ARString = ARString & "," & i
Next i
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(ARString), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
End Sub
I always want columns 8:12 but the rest may be shorter or longer depending on the data I'm importing. Is there a way to get that string into the command like I'm attempting or is there another, easier way to do it?