Range Class Fail, Subtotal Access to Excel VBA
Hey everyone,
I'm trying to subtotal data in an excel file but I am getting a subtotal method of Range class failed in the red text below. I have been trying to get this to work with no success. Any Ideas? Thank you!!:banghead:
Hey everyone,
I'm trying to subtotal data in an excel file but I am getting a subtotal method of Range class failed in the red text below. I have been trying to get this to work with no success. Any Ideas? Thank you!!:banghead:
Code:
Public Function SUMMARY()
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
With xlApp
Dim wb As Object
Dim ws As Object
Dim Lastrow As Long
Set wb = .Workbooks.Open("D:\Summary.xlsx")
Set ws = wb.Sheets(1)
ws.Columns("B").Delete xlShiftToLeft
[COLOR=red]ws.Range("A1:R91").Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, _[/COLOR]
[COLOR=red] 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18), Replace:=True, PageBreaks:=False, _[/COLOR]
[COLOR=red] SummaryBelowData:=True[/COLOR]
ws.ActiveSheet.Outline.ShowLevels RowLevels:=2
ws.Cells.EntireColumn.AutoFit
xlApp.Visible = True
.ScreenUpdating = False
LinkToFile = False
SaveWithDocument = True
wb.Close
End With
End Function
Last edited: