I am getting an object error on the following code
lc = Cells(11, Columns.Count).End(xlToLeft).Column
Range(Cells(11, lc - 6), Cells(70, lc)).Cut
Range(Cells(11, lc - 4)).Select
ActiveSheet.Paste
Please advise
I am getting an object error on the following code
lc = Cells(11, Columns.Count).End(xlToLeft).Column
Range(Cells(11, lc - 6), Cells(70, lc)).Cut
Range(Cells(11, lc - 4)).Select
ActiveSheet.Paste
Please advise
lc
is probably negative. Write this to see:
lc = Cells(11, Columns.Count).End(xlToLeft).Column
MsgBox lc
To make your code work, you have to pass String
in the Select range. Currently, you are passing a cell, and you need to add its address:
Sub TestMe()
Dim lc As Long
lc = 10
Range(Cells(11, lc - 6), Cells(70, lc)).Cut
Range(Cells(11, lc - 4).Address).Select
ActiveSheet.Paste
End Sub
Last, but not least, Select
and Activate
are considered a bad practice. Once you feel more secure in your VBA knowledge, try to avoid them - How to avoid using Select in Excel VBA.
lc = Cells(11, Columns.Count).End(xlToLeft).Column
Range(Cells(11, lc - 6), Cells(70, lc)).Cut(ActiveSheet.Cells(11, lc - 4))
After Cut - you declare destination of cut cells. Suppose to work.