+ Reply to Thread
Results 1 to 34 of 34

how to increment the number of a row unless the previous row does not contain a number

  1. #1
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    how to increment the number of a row unless the previous row does not contain a number

    Hello everyone,
    I am new to Excel, so bear with me.
    Trying to have a column in which every row increments by 1, unless the row before does not return a number (ie does not contain a formula).
    I am putting the number "1" in the 8th row of the first column ($A$8) and then I'd like to write a formula where the next cell below will return 2, the next cell after that returns 3, UNLESS one of the cells is empty (does not have a formula at all).
    I was using this forumala:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    How can I alter this formula so that it only applies if the cell above it actually does contain the formula?
    Thank you!

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: how to increment the number of a row unless the previous row does not contain a number

    Hi there.

    Your description is a bit ambiguous. But... a picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: how to increment the number of a row unless the previous row does not contain a number

    UNLESS one of the cells is empty (does not have a formula at all)
    Not possible if you are referencing the cell above in Column A.

    See attached

    =IF($B9="","",MAX($A$8:A8)+1)
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by Glenn Kennedy View Post
    Hi there.

    Your description is a bit ambiguous. But... a picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Sorry for the lack of screenshot...
    here it is:

    Attachment 764524

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: how to increment the number of a row unless the previous row does not contain a number

    Glenn is asking to see yur WORKBOOK, not a picture of it.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  6. #6
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by AliGW View Post
    Glenn is asking to see yur WORKBOOK, not a picture of it.
    I am sorry, I am new to Excel formulas... what is a workbook?

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: how to increment the number of a row unless the previous row does not contain a number

    Your excel file.... the .xlsx from which the screenshot came. A picture of your sheet is non-editable. I want to see a file, with an indication fo your expected results in it.

  8. #8
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    I am sorry Glenn, I am new here.
    Here's the example Excel sheet attached:
    Attached Files Attached Files
    Last edited by AliGW; 01-22-2022 at 05:34 AM. Reason: PLEASE don't quote unnecessarily!

  9. #9
    Registered User
    Join Date
    01-05-2022
    Location
    Indonesia
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    51

    Re: how to increment the number of a row unless the previous row does not contain a number

    do you mean :
    if the cell on the right is not empty, then auto increment the number from the very first line of data, and of empty it will be empty too, and if the cell below it has the data, the numbering will continue automatically?

    Edit : I make 2 tables with 2 different formula
    Attached Files Attached Files
    Last edited by muhammadridho30; 01-22-2022 at 12:40 AM.
    I'm not an expert, but I'll try

  10. #10
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Well actually I would like to base it on the row above, not the cell to the right and in particular I'd like a formula that doesn't reference a specific row with an absolute row address, but just references the row above with a -1 relative address because I have a ton of rows and they get moved around so they need to renumber automatically based on whether the row above has a number (or not renumber if the row above is empty). Make sense?
    Last edited by AliGW; 01-22-2022 at 05:35 AM. Reason: PLEASE don't quote unnecessarily!

  11. #11
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,036

    Re: how to increment the number of a row unless the previous row does not contain a number

    I don't think you have understood what you were told in Post 2. Any cell can have EITHER a value OR a formula. But not both.

    Your sample didn't help as there was no explanation in it. I am struggling to understand what you want.

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    Does this do what you want:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  13. #13
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: how to increment the number of a row unless the previous row does not contain a number

    Please Login or Register  to view this content.

    You will need VBA to do this BUT initially your "blank" cells will need a character [e.g. "X" ] entered to identify them as needing to be skipped.

    the attached is a simple example: the highlighted cells in column B had an "X" and the range was arbitrary value of B8:B30
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by TMS View Post
    Does this do what you want:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I need something that has only relative references to the rows, not absolute ones... can that be done?
    sort of like:
    - look at the previous row
    - if the previous row is a number then add 1 to that number
    - if the previous row is empty (or an X) don't do anything

    Is that possible?

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: how to increment the number of a row unless the previous row does not contain a number

    It can only be done with VBA and even then you will have to identify cells to be left blank (post #13).

    And how do we know when to stop adding the data ?

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: how to increment the number of a row unless the previous row does not contain a number

    Did you try what was suggested?

    Try this:

    =IF(OR(B8="",B8="x"),"",MAX($A$7:$A7)+1)

    $A$7 is an absolute reference, but $A7 is relative and will increment as you drag copy down.

    Try it.

    If you want this all in column A with no reference to column B, then as has been pointed out already, it can't be done with a formula, and you;ll need to go down the VBA route.

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    As Ali said, $A7 is not an absolute row reference. Space or "x" is a new requirement, as far as I can tell, so not included in my solution. Looks like Ali has done the necessary tinkering

  18. #18
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    After some googling I found a way (INDIRECT) to reference the previous row's value without an absolute reference, so I am using this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and it works to get the previous row's value and increment it by one...

    So I just need some help with the if/then/else statement...
    I tried this to no avail:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    In A8:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    dragged down as far as you need. If you subsequently delete the formula in a cell, the count will move down.

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    May be better to use INDEX.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    No luck with either of those...
    also I am trying to stay away from absolute references because i will have rows where i want numbers and empty rows...
    1
    2
    3
    x
    4
    5
    x
    6
    7
    8
    etc

  22. #22
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    nope, no luck

    I am attaching the example for where I am at now

  24. #24
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number


  25. #25
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: how to increment the number of a row unless the previous row does not contain a number

    If you want a formula to drag down

    in A9

    =MAX($A$8:A8)+1

    then just delete formula entries where you want a blank or add in non-numeric data
    Last edited by JohnTopley; 01-24-2022 at 10:51 AM.

  26. #26
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: how to increment the number of a row unless the previous row does not contain a number

    Please try A1 (then copy down and delete some cells that you want)

    =IF(ISNUMBER(OFFSET(A1,-1,0,,)),MAX(OFFSET(A1,-ROW(A1)+1,0,ROW(A1)-1))+1,"")

    note : this formula will add 1 from max of all above cells

    Regards.

  27. #27
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by menem View Post
    Please try A1 (then copy down and delete some cells that you want)

    =IF(ISNUMBER(OFFSET(A1,-1,0,,)),MAX(OFFSET(A1,-ROW(A1)+1,0,ROW(A1)-1))+1,"")

    note : this formula will add 1 from max of all above cells

    Regards.
    I am not able to get any results out of this with this in A1 or in any other cell of the same column.
    Could you send an XLS example file?

  28. #28
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by JohnTopley View Post
    If you want a formula to drag down

    in A9

    =MAX($A$8:A8)+1

    then just delete formula entries where you want a blank or add in non-numeric data
    The dragging down works but unfortunately when I delete a cell anywhere (or add a row) the rows don't renumber automatically (which is what I need)

  29. #29
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: how to increment the number of a row unless the previous row does not contain a number

    Removed by JT
    Last edited by JohnTopley; 01-29-2022 at 01:20 PM.

  30. #30
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    Pretty sure post #24 worked for that.

  31. #31
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    The formula in the workbook in post #24 assumes you copy it down as far as you wish. Then you can clear the formula from any cell, or replace the formula with any alphabetic text. You CANNOT put a numeric value in.

  32. #32
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    You guys are right. I had not dragged it down.
    THANK YOU ALL SO MUCH for helping me with this. It will make my work so much easier!
    THANK YOU!

  33. #33
    Registered User
    Join Date
    01-21-2022
    Location
    New York
    MS-Off Ver
    NeoOffice Version: 2017.32
    Posts
    13

    Re: how to increment the number of a row unless the previous row does not contain a number

    Quote Originally Posted by TMS View Post
    Updated. Please check.
    Thank you @TMS
    Wanted to thank you personally for helping with this! Your formula makes my life soooo much easier!
    Thank you for taking the time!
    I've marked this post as resolved thanks to you!

  34. #34
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: how to increment the number of a row unless the previous row does not contain a number

    You're welcome.

+ 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. Replies: 8
    Last Post: 07-08-2021, 04:11 AM
  2. [SOLVED] locate a number in a row and change it to another number and increment by 1.
    By chelsea7A in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-30-2018, 04:23 PM
  3. [SOLVED] How to increment only Number in list when it contains both Number and Alphabets
    By gauravchugh2k in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-29-2014, 12:42 AM
  4. Search worksheet for certain text + number combo and then increment the number
    By hal9000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2013, 06:09 PM
  5. Replies: 0
    Last Post: 09-06-2012, 10:41 AM
  6. Replies: 3
    Last Post: 03-15-2010, 02:33 PM
  7. [SOLVED] change cell shading when a number differs from the previous number
    By zooeyhallne in forum Excel General
    Replies: 1
    Last Post: 06-06-2005, 06:05 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