+ Reply to Thread
Results 1 to 8 of 8

Insert Row based on Condition and add data in the newly created rows

  1. #1
    Registered User
    Join Date
    07-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2013
    Posts
    5

    Insert Row based on Condition and add data in the newly created rows

    Hello all,

    I would like to know how to:
    1. insert a row in between two rows that meet the following condition (example with rows 2 and 3): A2 < A3 - 1
    2. when the row is added (let's name it row number K), I want to fill the cell AK with the following: value of AK = value of A(K-1) + 1
    3. repeat this until for any row (number N) except the last one, I have the following: value of AN = Value of A(N+1) - 1


    Example:

    If my current sheet shows the following:

    A1 = 8
    A2 = 9
    A3 = 15
    A4 = 17
    A5 = 18


    I would like to get to this:

    A1 = 8
    A2 = 9
    A3 = 10
    A4 = 11
    A5 = 12
    A6 = 13
    A7 = 14

    A8 = 15
    A9 = 16
    A10 = 17
    A11 = 18


    (The cells in bold belong to the newly created rows)


    Thank you

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Insert Row based on Condition and add data in the newly created rows

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Insert Row based on Condition and add data in the newly created rows

    Perfect 10 !!

    Thank you very much AlphaFrog

  4. #4
    Registered User
    Join Date
    07-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Insert Row based on Condition and add data in the newly created rows

    What if I want to add more data?

    Ideally, I would like to the new row (N) to show this:

    AN = A (N-1)
    BN = B (N-1)
    CN = C (N-1) + 1
    EN = FN = GN = 0
    HN = H (N-1)
    IN = I (N-1)

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Insert Row based on Condition and add data in the newly created rows

    Quote Originally Posted by Omariss View Post
    What if I want to add more data?

    Ideally, I would like to the new row (N) to show this:

    AN = A (N-1)
    BN = B (N-1)
    CN = C (N-1) + 1
    EN = FN = GN = 0
    HN = H (N-1)
    IN = I (N-1)
    I don't follow. The nomenclature is confusing and contra to the existing cell coordinates in Excel (column letter & row number). Just show a before and after, and describe what you want to add.

  6. #6
    Registered User
    Join Date
    07-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Insert Row based on Condition and add data in the newly created rows

    Sorry, I'm new to this.

    I want to change the condition (mentioned in bullet point n°2 in my first message) to something more complex.

    For example if a row is inserted between rows 3 and 4 I would like the new row 4 to show the following:

    A4=A3
    B4=B3
    C4=C3 + 1
    E4=G4=H4=0
    F4=F3
    I4=I3
    J4=J3


    Thanks

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Insert Row based on Condition and add data in the newly created rows

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Insert Row based on Condition and add data in the newly created rows

    Absolutely amazing!

    Many thanks AlphaFrog.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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