Selection.Insert Shift:=xlDown

goncalo_2697

New Member
Joined
Jan 2, 2023
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Hi, I'm trying to run the following code to add one empty line, but it only works if I run the macro as soon as I open the excel:

VBA Code:
Sub LinhasAuto()
    Dim lRow As Long
Dim RepeatFactor As Variant

    lRow = 11
    Do While (Cells(lRow, "A") <> "")
          
        RepeatFactor = Cells(lRow, "AO")
        If ((RepeatFactor > 0) And IsNumeric(RepeatFactor)) Then
                  
           Range(Cells(lRow, "A"), Cells(lRow, "AT")).Copy
           Range(Cells(lRow + 1, "A"), Cells(lRow + RepeatFactor, "AT")).Select
           Selection.Insert Shift:=xlDown
             
           lRow = lRow + RepeatFactor
        End If
      
        lRow = lRow + 1
    Loop
End Sub


If i change anything in the file after open it up and before run the code, I get the error attached.

Thanks for your help!

Also asked here ERROR Selection.Insert Shift:=xlDown
and here Selection.Insert Shift:=xlDown
 

Attachments

  • Capturar.JPG
    Capturar.JPG
    15 KB · Views: 17
Last edited by a moderator:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top