Thread: [Solved] Code for column button?
View Single Post
 
Old 12-13-2016, 08:15 PM
cloudforgiven cloudforgiven is offline Windows XP Office 2013
Novice
 
Join Date: Nov 2016
Posts: 13
cloudforgiven is on a distinguished road
Default Code for column button?

Hi I am new to excel 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 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 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 spreadheet and I only want it to generate a column until the last row of my table?
HELP?


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

Last edited by cloudforgiven; 12-14-2016 at 08:37 AM.
Reply With Quote