Insert New Column in Table Excel VBA

前端 未结 3 871
星月不相逢
星月不相逢 2021-01-02 23:34

I\'m running into some issues on a worksheet that I\'m building. I want to insert a column at a specific location in a table and then set the header.

I searched aro

3条回答
  •  自闭症患者
    2021-01-02 23:48

    It is possible to add a column to a table in a particular place and name it, using the same line of code.

    Table.ListColumns.Add(2).Name = "New Header"
    

    This will add a column to the left of the second column in the table and name it New Header. You can make your code dynamic by adding a column to the left of one that you know the name of. This way, it is not necessary to specify the integer value of a new column's fixed location.

    Dim newColNum as Integer
    newColNum = Range("Table[Column Name]").Column
    Table.ListColumns.Add(newColNum).Name = "New Header"
    

    [Column Name] is the name of the column in your table where you want to insert a new column. It can have any position in the table, and you can pass it's value as an integer to the Add.

提交回复
热议问题