Hi I am new to vba programming 2013 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 this button which is an activex control. The column will end based on how many rows there are in my table, meaning if there are 10 rows I should not see a column on line 11 of the spreadsheet. Also here is what I have so far, please check below. My issue is that it generates the column that I want, but it does so for the whole column of that spreadheet and I only want it to generate a column until the last row of my table?
You can run the code in excel with a button if you want to see what it does, just to see what I am talking about.
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