cloudforgiven
New Member
- Joined
- Nov 21, 2016
- Messages
- 21
Hi I am new to excel 2013 vba programming so bare with me.
This code is suppose to generate a column at the location the user specified, and the column is suppose to end where the table ends, meaning if I have a 10 row table the last column box would be at 10, not line 11.
Now the code blow is suppose to do that but I keep getting an error where I put the ' ' marks. The error is a type mismatch and I dont know why? Any ideas?
The line I get the error is suppose to copy the A column, clear the contents of the copied version then paste that into the new location the user inputted.
Now I tried using macros to do this but the problem is that I cannot specify a Range because the table's rows and columns sizes are constantly changing, so I would have to manually edit the macro's range which I dont want to do.
The code works meaning it generates the column where the user wants it to, however the lines or boxes around the cells so that you are aware that its an extension of the table are not generated which means its not copying correctly. here is img: Imgur: The most awesome images on the Internet
here is code:
Dim x AsVariant
Dim ColumnNum%
x = InputBox("Enter a column that you want to add: ","What column?")
If x =""ThenExitSub
ColumnNum = x
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).Insert shift:=xlRight
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum - 1).Range("A" & ColumnNum).Copy 'error occurs here'
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).ClearContents
This code is suppose to generate a column at the location the user specified, and the column is suppose to end where the table ends, meaning if I have a 10 row table the last column box would be at 10, not line 11.
Now the code blow is suppose to do that but I keep getting an error where I put the ' ' marks. The error is a type mismatch and I dont know why? Any ideas?
The line I get the error is suppose to copy the A column, clear the contents of the copied version then paste that into the new location the user inputted.
Now I tried using macros to do this but the problem is that I cannot specify a Range because the table's rows and columns sizes are constantly changing, so I would have to manually edit the macro's range which I dont want to do.
The code works meaning it generates the column where the user wants it to, however the lines or boxes around the cells so that you are aware that its an extension of the table are not generated which means its not copying correctly. here is img: Imgur: The most awesome images on the Internet
here is code:
Dim x AsVariant
Dim ColumnNum%
x = InputBox("Enter a column that you want to add: ","What column?")
If x =""ThenExitSub
ColumnNum = x
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).Insert shift:=xlRight
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum - 1).Range("A" & ColumnNum).Copy 'error occurs here'
ThisWorkbook.Sheets("Sheet1").Columns(ColumnNum).ClearContents