Rafa0173
12-15-2022, 07:18 AM
Hello folks!
I've recorded this macro on Excel 2016 and it has been working perfectly.
Sub Inserir()
'
' Inserir Macro
'
' Atalho do teclado: Ctrl+i
'
Range("A3:H3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A4:H4").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A4:B4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=16
Range("C2000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2001:H2001").Select
Selection.ClearContents
Range("A1").Select
End Sub
But my worksheet has 28 sheets, numbered from 2 to 29 and currently I need to run this macro individually in each sheet. So obviously I've tried to make a loop with this macro:
Sub Inserir()
'
' Inserir Macro
'
' Atalho do teclado: Ctrl+i
'
For aba = 2 To 29
Sheets(aba).Activate
Range("A3:H3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A4:H4").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A4:B4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=16
Range("C2000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2001:H2001").Select
Selection.ClearContents
Range("A1").Select
Next aba
End Sub
I've tried a lotta things but I simply can't make it work. I'm reciving this error message:
Error '1004':
This won't work because it would move cells in a table on your worksheet.
Any help here? Tks a lot!
I've recorded this macro on Excel 2016 and it has been working perfectly.
Sub Inserir()
'
' Inserir Macro
'
' Atalho do teclado: Ctrl+i
'
Range("A3:H3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A4:H4").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A4:B4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=16
Range("C2000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2001:H2001").Select
Selection.ClearContents
Range("A1").Select
End Sub
But my worksheet has 28 sheets, numbered from 2 to 29 and currently I need to run this macro individually in each sheet. So obviously I've tried to make a loop with this macro:
Sub Inserir()
'
' Inserir Macro
'
' Atalho do teclado: Ctrl+i
'
For aba = 2 To 29
Sheets(aba).Activate
Range("A3:H3").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A4:H4").Select
Selection.Copy
Range("A3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A4:B4").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.End(xlDown).Select
ActiveWindow.SmallScroll Down:=16
Range("C2000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2001:H2001").Select
Selection.ClearContents
Range("A1").Select
Next aba
End Sub
I've tried a lotta things but I simply can't make it work. I'm reciving this error message:
Error '1004':
This won't work because it would move cells in a table on your worksheet.
Any help here? Tks a lot!