Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Posts
    989
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert rows across sheets (xp)

    I recorded part of the following:
    Sub ExampleOfInsertingARow()
    Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
    Sheets("Sheet1").Activate
    Range("A5").EntireRow.Insert
    End Sub

    .. and want it to insert a row at row 5 for ALL of the selected sheets, but it only inserts a row in the first sheet?! I tried removing the line that Activates Sheet1, but it still doesn't work. Any ideas? Andy.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert rows across sheets (xp)

    I would do it like this:

    Sub Foo()
    Dim oSh as Worksheet
    For Each oSh in ActiveWindow.SelectedSheets
    oSh.Range("A5").Rows.Insert
    Next
    End Sub
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Insert rows across sheets (xp)

    I would do this:

    <pre>Sub ExampleOfInsertingARow()
    Dim oSht As Worksheet
    For Each oSht In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
    oSht.Range("A5").EntireRow.Insert
    Next oSht
    End Sub
    </pre>

    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •