rorobear
09-02-2021, 08:34 AM
Hello Everyone,
Was wondering if I could get a little VBA help with Table project. I have the code below that works just fine, but I’d like to modify it a little bit.
1. I’d like the code to be specific to the tables in the workbook, (meaning I don’t want to add columns outside of the table)
2. I only want one column at time and 1 Inputbox that will prompt the user to add the column to the left or right of the active cell.
I tried various combinations using listColumns(iCol) or listColumns.ActiveCell etc. none of which work, so I’m reaching out for a little help. The workbook is included. Thank you as always for any assistance.
Private Sub CommandButton1_Click()
Dim iCol As Long
Dim iCount As Long
Dim i As Long
'to get the number of columns that you want to insert with an input box
iCount = InputBox(Prompt:="How many column you want to add?")
'to get the column number where you want to insert the new column
iCol = InputBox(Prompt:= _
"After which column you want to add new column? (Column number)")
'loop to insert new column(s)
For i = 1 To iCount
Columns(iCol).EntireColumn.Insert
Next i
End Sub
Was wondering if I could get a little VBA help with Table project. I have the code below that works just fine, but I’d like to modify it a little bit.
1. I’d like the code to be specific to the tables in the workbook, (meaning I don’t want to add columns outside of the table)
2. I only want one column at time and 1 Inputbox that will prompt the user to add the column to the left or right of the active cell.
I tried various combinations using listColumns(iCol) or listColumns.ActiveCell etc. none of which work, so I’m reaching out for a little help. The workbook is included. Thank you as always for any assistance.
Private Sub CommandButton1_Click()
Dim iCol As Long
Dim iCount As Long
Dim i As Long
'to get the number of columns that you want to insert with an input box
iCount = InputBox(Prompt:="How many column you want to add?")
'to get the column number where you want to insert the new column
iCol = InputBox(Prompt:= _
"After which column you want to add new column? (Column number)")
'loop to insert new column(s)
For i = 1 To iCount
Columns(iCol).EntireColumn.Insert
Next i
End Sub