Create Table in Excel Worksheet using VBA

后端 未结 1 920
粉色の甜心
粉色の甜心 2021-02-09 06:10

I have this code below that will auto select a range. Does anyone know how I can add code to create a table to the selected range?

Thanks!

Sub DynamicRan         


        
1条回答
  •  无人共我
    2021-02-09 06:28

    Use the following Excel VBA code snippet to add the Table object corresponding to selected Range:

    Dim objTable As ListObject
    Set objTable = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
    

    You can also apply optional styling to the added Table object like shown below:

    objTable.TableStyle = "TableStyleMedium2"
    

    More details available at MSDN: https://msdn.microsoft.com/en-us/library/office/ff823155.aspx

    Hope this will help.

    0 讨论(0)
提交回复
热议问题