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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,033
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
 

SeanOZ

New Member
Joined
Oct 31, 2019
Messages
13
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
 

SeanOZ

New Member
Joined
Oct 31, 2019
Messages
13
Thank you so much for your help with my question.

Kind regards,

Sean
 
Last edited by a moderator:

Forum statistics

Threads
1,077,662
Messages
5,335,561
Members
399,024
Latest member
rokcel389

Some videos you may like

This Week's Hot Topics

Top