Button to add column to the end of a table

gaudrco

Board Regular
Joined
Aug 16, 2019
Messages
203
Hi,

I would like to be able to assign a command button to add a new column to the end of my table. Each new column added should appear to the right of the last new column add. The command button will be on the activesheet but the table in which I am trying to add columns to will be on sheet “Competitor Overview Data”. My table range is from D4:S52 and the name of the range is “CompTable”.

Any ideas?
 
Hi, you could try this to copy the formatting of the cells outside of the table.

Code:
Private Sub CommandButton2_Click()
With Sheets("Competitor Overview Data").ListObjects("CompTable")
    .ListColumns.Add (.ListColumns.Count + 1)
    .ListColumns(.ListColumns.Count - 1).Range.EntireColumn.Copy
    .ListColumns(.ListColumns.Count).Range.EntireColumn.PasteSpecial Paste:=xlPasteFormats
End With
End Sub
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Fantastic! I really appreciate all of the help.

There is more that I would like to add to this macro but Iwonder if I should start a new thread. It involves inserting column headers to thesenew columns based off the value of Cell A1. My goal is to have an input cell(A1) where people can input new competitors. When they type in a name to A1 andpress this button, the columns are created with the value of A1 in the header.Then the contents of A1 will clear.

 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,746
Members
449,050
Latest member
excelknuckles

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