VBA Excel小计错误

我收到了下面的代码错误箱:“范围类的小计方法失败”。 我怎样才能解决这个问题,我怎样才能重写代码,以便它可以容纳不断变化的列数小计?

Range("A1").Select Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(14, 15, 16 _ , 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, _ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63), Replace:= _ True, PageBreaks:=False, SummaryBelowData:=True 

如果这是一个数组,你可以像下面这样构build它

 Dim ArrayNumbers() As String Dim CounterArray As Long For CounterArray = 1 To 49 ReDim Preserve ArrayNumbers(CounterArray) 'I'm not quite sure if parsing empty elements in the 'Total List' arg would give error, so instead we are going to start in the element 1 of the array doing the value 14 for it and so on. ArrayNumbers(CounterArray) = IIf(CounterArray <> 1, "," & CounterArray+14, CounterArray+14) 'this is to avoid the comma in the first value just for all the other ones Next CounterArray Range("A1").Select Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=ArrayNumbers, Replace:= _ True, PageBreaks:=False, SummaryBelowData:=True