Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBS in Excel (Excel XP)

    I need to be able to insert rows after a named cell in a spreadsheet. I have 5 named cells in this spreadsheet. I am having trouble figuring out how to record this in a macro. Could someone help me with this? Thank you,
    Rick

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBS in Excel (Excel XP)

    Assuming you mean VBA (Visual Basic for Applications, the programming language built into Excel) instead of VBS (Visual Basic Scripting), you could use this:

    Sub InsertRowAfterNamedCell(strName As String)
    Range(strName).Offset(1, 0).EntireRow.Insert
    End Sub

    Sub InsertRowAfterNamedCells()
    InsertRowAfterNamedCell "FirstName"
    InsertRowAfterNamedCell "SecondName"
    InsertRowAfterNamedCell "ThirdName"
    InsertRowAfterNamedCell "FourthName"
    InsertRowAfterNamedCell "FifthName"
    End Sub

    Replace FirstName etc. by the names in your spreadsheet.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: VBS in Excel (Excel XP)

    You may need to explain a bit more about what you are doing. This code will insert 3 rows after the named range "ralph" on worksheet "Sheet1":

    Worksheets("Sheet1").Range(Range("ralph").Offset(1 , 0), _
    Range("ralph").Offset(3, 0)).EntireRow.Insert shift:=xlDown

    (The " _" is just to break a long line of code.)
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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