简体   繁体   中英

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:

在此处输入图片说明

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

在此处输入图片说明

Thank you :-)

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM