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: 19
Last edited by a moderator:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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