Enabling the Total Row via Macro

Folksteve

New Member
Joined
Jun 2, 2014
Messages
10
Hello,

I've built the below Macro to take information from one sheet and put it into a new workbook as a Table.

Problem is I need to add a total row and when I go the usual route of 'ActiveSheet.ListObjects("Table1").ShowTotals = True' I get 'Run-time error '1004': Application-defined or Object-defined error'

Sub Generate_New_Sheet()
'Change to the relevant sheet'
'Create a new workbook with the relevant sheet'
ThisWorkbook.Sheets("Sheet2").Copy
'Save the new workbook to the Desktop'
ActiveWorkbook.SaveAs Filename:=Environ("USERPROFILE") & "\Desktop\" & "TEST - " & Format(Now, "dd-mm-yy"), FileFormat:=xlOpenXMLWorkbook
'Pause Screen Updating'
Application.ScreenUpdating = False
'Delete All Comments'
Cells.Select
Selection.ClearComments
'Unprotect Sheet'
ActiveSheet.Unprotect
'Modify Header & Footer'
ActiveSheet.PageSetup.CenterHeader = "DATA"
ActiveSheet.PageSetup.CenterFooter = ""
ActiveSheet.PageSetup.RightFooter = "&D"
'Delete Unecessary Columns'
Columns("B:I").EntireColumn.Delete
Columns("C").EntireColumn.Delete
Columns("H").EntireColumn.Delete
'Delete Blank Rows based on Weight Column'
Range("D:D").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'Delete Stored Data Rows'
Rows("2:195").EntireRow.Delete
'Change to Text'
[A1].Value = "'Text"
'Unfreez Panes'
ActiveWindow.FreezePanes = False
'Set Zoom'
ActiveWindow.Zoom = 125
'Show ONLY Active Rows'
lcol = Cells(1, Columns.Count).End(xlToLeft).Column
lrow = Cells(Rows.Count, "D").End(xlUp).Row
Range(Cells(1, lcol + 1), Cells(Rows.Count, Columns.Count)).EntireColumn.Hidden = True
Range(Cells(lrow + 1, 1), Cells(Rows.Count, Columns.Count)).EntireRow.Hidden = True
'Select Active Cells'
Range("A:G").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
'Create Table'
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
tbl.TableStyle = ""
ActiveSheet.ListObjects("Table1").ShowTotals = True
'Set Print Area'
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintArea = Range("A1" & LR).SpecialCells(xlCellTypeVisible).Address
End With
'Move back to cell A1'
Range("A1").Select
'Reactivate Screen Update'
Application.ScreenUpdating = True
End Sub


Thanks for any help you can give
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
It worked for me if I change that line to read:

Code:
tbl.ShowTotals = True

Jeff
 
Upvote 0
Thanks Jeff, I'm afraid I'm getting the same error using tbl.ShowTotals = True :(

I'm using Excel 2007 if that helps.
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top