daniele3004
daniele3004

Reputation: 13920

How to create Excel Table by VBA at runtime?

During execution of macro I reads multiple excel file and creates a new excel file, i build a similar sheet:

enter image description here

At runtime by VBA I want to set this area and create a table, add Total Row and get the following result:

enter image description here

Thank you :-)

Upvotes: 0

Views: 735

Answers (1)

AnalystCave.com
AnalystCave.com

Reputation: 4974

Like this:

Range("A1:I9").Select
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$I$9"), , xlYes).Name = "Table1"
ActiveSheet.ListObjects("Table1").ShowTotals = True
ActiveSheet.ListObjects("Table1").ListColumns("B").TotalsCalculation = xlTotalsCalculationSum
ActiveSheet.ListObjects("Table1").ListColumns("C").TotalsCalculation = xlTotalsCalculationSum
'Repeat row above until column I

I got this by recording a VBA Macro. If you are not familiar with Macro recording see link here.

Upvotes: 1

Related Questions