Rows() error 1004 VBA

btbdn

New Member
Joined
Sep 3, 2014
Messages
3
Sub Macro15()
'
' Macro15 Macro
'

'
Sheets("Plan4").Select
' the error start here
Rows(3).Select
Selection.EntireRow.Hidden = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.EntireRow.Hidden = True
Range("A2:L2").Select
Selection.Copy
Range("A4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A2").Select
Sheets("Plan4").Select
ActiveCell.FormulaR1C1 = "=Plan4!R[2]C+1"
ActiveCell.Offset(1, 0).Range("A1").Select
Sheets("Controle").Select
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Where did you put your VBA code? It needs to be in a General module like Module1, not a Worksheet module.
 
Upvote 0
Needs to be in a general module not a worksheet module
As an aside. There is very few reasons to select a range to work with it. For example, the same thing your code is doing can be done slightly more efficiently like this:
Code:
Sub Test15()

With Sheets("Plan4")
    .Rows(3).EntireRow.Hidden = False
    .Rows(3).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    .Rows(3).EntireRow.Hidden = True
    .Range("A2:L2").Copy
    .Range("A4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Application.CutCopyMode = False
    .Range("A2").FormulaR1C1 = "=Plan4!R[2]C+1"
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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