group sheets- insert row by : range.select EntireRow.insert

mostafaghih

New Member
Joined
Feb 11, 2017
Messages
2
I am getting confused that why excel do the actions to all grouped sheets except this action that I really need it.
I want to insert Row by selecting range of cells and then insert entire row.
it makes me more confused that it works when I do it manually and also recording macro. I mean all grouped sheets row is inserted. but when I run the recorded macro it just insert a row just to the activated sheet but not to all selected sheets. here is the codes:
thanks for your help.

sub macro1()

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
Range("B5:D5").Select
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove

end sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You would normally loop though the sheet array to insert rows.....

Code:
Sub Test1()
    Dim myNme, shtNmes, myrow As String
    
    shtNmes = Array("Sheet1", "Sheet2", "Sheet3")
    myrow = Selection.Address
    
    For Each myNme In shtNmes
        With Worksheets(myNme)
            .Range(myrow).EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
        End With
    Next myNme

End Sub
 
Upvote 0
Actually the With statement was pointless in my last post

Code:
Sub Test1()
    Dim myNme, shtNmes, myrow As String
    
    shtNmes = Array("Sheet1", "Sheet2", "Sheet3")
    myrow = Selection.Address
    
    For Each myNme In shtNmes
       Worksheets(myNme).Range(myrow).EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
    Next myNme

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,562
Messages
6,125,546
Members
449,237
Latest member
Chase S

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