Macro Button for adding a column in a specific location

SeanOZ

New Member
Joined
Oct 31, 2019
Messages
13
Hi,

I am very much a beginner with excel, but wanting to add a button on my spreadsheet to add a column after a specific column.

The code I have put together is as follows:
Sub AddColumns()
Dim varUserInput As Variant
varUserInput = InputBox("Enter Column Letter where you want to add a column:", _
"What Column?")
If varUserInput = "" Then Exit Sub


MyRange = varUserInput
' Store the selected range in a variable.
Set MyRange = Selection
' Select the entire column.
Selection.EntireColumn.Select
' Insert Columns in all selected sheets.
Selection.Insert
' Reselect the previously selected cells.
MyRange.Select
End Sub

This does not work though.

I also want to add a button to bring up a box to ask me to delete a specific row and also one to delete a specific column so basically I will have 3 buttons.

I already have a button to add a specific row.

Thanks so much for your help in advance.

Sean
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You have about three request here.

Try this to insert the column:
Code:
Sub AddColumns()
'Modified  11/1/2019  12:55:39 AM  EDT
On Error GoTo M
Dim varUserInput As Variant
varUserInput = InputBox("Enter Column Letter where you want to add a column:", _
"What Column?")
If varUserInput = "" Then Exit Sub
Columns(varUserInput).Insert
Exit Sub
M:
MsgBox "You did not enter a letter character into the InputBox" & vbNewLine & "Try again"
End Sub
 
Upvote 0
Thank you so much for all your help and your quick response to my question.

Kind regards,

Sean

You have about three request here.

Try this to insert the column:
Code:
Sub AddColumns()
'Modified  11/1/2019  12:55:39 AM  EDT
On Error GoTo M
Dim varUserInput As Variant
varUserInput = InputBox("Enter Column Letter where you want to add a column:", _
"What Column?")
If varUserInput = "" Then Exit Sub
Columns(varUserInput).Insert
Exit Sub
M:
MsgBox "You did not enter a letter character into the InputBox" & vbNewLine & "Try again"
End Sub
 
Upvote 0
Thank you so much for your help with my question.

Kind regards,

Sean
 
Last edited by a moderator:
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
Do you still need more help?



Thank you so much for your help with my question.

Kind regards,

Sean
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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