Button to add columns on spreadsheet?

Status
Not open for further replies.

cloudforgiven

New Member
Joined
Nov 21, 2016
Messages
21
Hi I am new to excel 2013 vba programming and was hoping if someone can help me. I am trying to add 1 blank column to a spreadsheet based on the user input after they click a button that is an activex control. The column will end based on how many rows there are in my table, meaning if there are 10 rows, after the user clicks the button an inputs where they want the column to be, I should not see a column box on line 11 of the spreadsheet.
Now I've managed to do this my issue is below:

My issue is the cells the button generate
does not include the lines or boxes around the cells so that you are aware that its an extension of the table? Any Ideas?
here is what I mean: Imgur: The most awesome images on the Internet notice the I column there are no lines??
Here is code, I think I am missing a copy function after the line shift:=xlRight, but I don't know how to implement it?

I don't want to use macros because since the tables rows and column change I will have to constantly hard-code the range into the macro which i dont want,trust me I tried it an its annoying.

Private Sub CommandButton2_Click()
Dim x As Variant
Dim ColumnNum

x = InputBox("Enter a column that you want to add: ", "What column?")
If x = "" Then Exit Sub
ColumnNum = x

ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).I nsert shift:=xlRight


ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).C learContents
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Status
Not open for further replies.

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,058
Latest member
oculus

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