+ Reply to Thread
Results 1 to 6 of 6

Insert New Row Above Text

  1. #1
    Registered User
    Join Date
    01-08-2015
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    21

    Insert New Row Above Text

    I would like to insert a new row above a cell that contains the text "Full Services" in column B. Here is my macro, however it is stuck in an infinite loop, and does not stop at just inserting a single row.

    Sub PrelimInsert()
    Dim c As Range
    For Each c In Range("B:B")
    If c.Value = "FULL SERVICES" Then c.Offset(-1, 0).EntireRow.Insert
    End If
    Next c

    End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Insert New Row Above Text

    You should loop from the bottom up when inserting rows. Try:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-08-2015
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    21

    Re: Insert New Row Above Text

    Works perfect, thank you!

    Additional question, at Rows(i).Insert, is it possible to add

    Rows(i).Offset(#,0).Insert

    where # equals the value of a cell, such as O2 for example. Would that be the indirect function?

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Insert New Row Above Text

    I don't understand. You want to insert a row with a cell value?

  5. #5
    Registered User
    Join Date
    01-08-2015
    Location
    NYC
    MS-Off Ver
    2010
    Posts
    21

    Re: Insert New Row Above Text

    No, Im sure I described it wrong, I would like to have the location of the new inserted row to be dependent on the value of a specific cell. Such as if the cell = 2, then the new row will be inserted two rows before "Full Services" Cell. If the value is 3, then it would be 3 rows before, and so on.
    Last edited by StudioLETA; 09-15-2015 at 09:31 AM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Insert New Row Above Text

    Try:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Look for specific text string, insert row below, insert text to that row
    By jwats in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2015, 03:08 PM
  2. Macro that will insert a simple text string in top cell of text file
    By Davek11 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2014, 07:31 PM
  3. Replies: 4
    Last Post: 07-17-2014, 12:04 PM
  4. [SOLVED] VBA codes to insert the rows and copy the first entire row text and insert sheet
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2013, 05:05 AM
  5. Replies: 3
    Last Post: 03-08-2012, 12:07 PM
  6. Replies: 12
    Last Post: 10-03-2008, 09:02 AM
  7. text box insert in Excel - text box lines print on second copy
    By Diana (Berry & Co) in forum Excel General
    Replies: 0
    Last Post: 07-25-2006, 11:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1