Run-time error when copying entire row!

  • Thread starter Thread starter Kieranz
  • Start date Start date
K

Kieranz

Hi
I have the following code:
ActiveSheet.Range("LastLine").Select 'range name
ActiveCell.Offset(-1, 0).EntireRow.Copy
Selection.EntireRow.Insert
Application.CutCopyMode = False
Range("Lastline").Offset(-1, 0).Select

On my lastline i have totals for various columns. So i copy the entire row of the previous row and insert it after the copied row or before the totals row/lastline. I get the following error on the code line 'Selection.EntireRow.Insert'
first "Run-time error '-2147417848 (80010108)':
Method 'Insert' of object 'Range' failed." When i run the debug and press F5 in VBE i get another error "Run-time error '1004' Insert method of Range class failed". Then Excel freezes and have to crash out.
I can't figure out the error, any help will be appreciated.
Many thanks
Kieranz
 
Hi,

Try this method. It worked for me.

With ActiveSheet.Range("LastRow")
.Offset(-1, 0).EntireRow.Copy
.Insert (xlDown)
Application.CutCopyMode = False
.Offset(-1, 0).Select
End With

-Ben
 
Hi,



Try this method. It worked for me.



With ActiveSheet.Range("LastRow")

.Offset(-1, 0).EntireRow.Copy

.Insert (xlDown)

Application.CutCopyMode = False

.Offset(-1, 0).Select

End With



-Ben
Ben many thks. Will try that. Although couldn't understand what wrong with my code
K
 
K,

I'm not sure why your code wasn't working. I tried it on my computer and it worked fine. I wonder if you may have the sheet protected. Turning on protection caused your code to break on the same line as you mention in your post.

Ben
 
Kieranz said:
Ben many thks. Will try that. Although couldn't understand what wrong with my code


Nothing is wrong.
It works fine.
However after you insert row, recalculation is triggered and something
else, somewhere else is crashing.

Try you code on empty workbook and check if it works or not. It should.
Try to switch to manual calculation and see if that works in you
application.

Generally using .select is not a good idea.
 
Kieranz wrote:








Nothing is wrong.

It works fine.

However after you insert row, recalculation is triggered and something

else, somewhere else is crashing.



Try you code on empty workbook and check if it works or not. It should.

Try to switch to manual calculation and see if that works in you

application.



Generally using .select is not a good idea.

Witek and Ben
Yes, i have a protect some where in the code. Thks again K
 
Back
Top