Andy2011
08-24-2015, 12:02 PM
Hi
I have used the following code to dynamically add a column to the right of the last column at the time of running the code. It seems to work, however if I then delete one or more of the columns the macro will not work again unless I save the spreadsheet first.
Sub InsertColumn()
Dim lastColumn As Long
lastColumn = ActiveSheet.Range("A1").SpecialCells(xlCellTypeLastCell).Column
Columns(lastColumn).Copy Destination:=Columns(lastColumn + 1)
End Sub
Anyone got any ideas why?
I have used the following code to dynamically add a column to the right of the last column at the time of running the code. It seems to work, however if I then delete one or more of the columns the macro will not work again unless I save the spreadsheet first.
Sub InsertColumn()
Dim lastColumn As Long
lastColumn = ActiveSheet.Range("A1").SpecialCells(xlCellTypeLastCell).Column
Columns(lastColumn).Copy Destination:=Columns(lastColumn + 1)
End Sub
Anyone got any ideas why?