goncalo_2697
New Member
- Joined
- Jan 2, 2023
- Messages
- 1
- Office Version
- 2013
- Platform
- 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:
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
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
Last edited by a moderator: