+ Reply to Thread
Results 1 to 21 of 21

Finding gaps within rows of numbers

  1. #1
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Finding gaps within rows of numbers

    Hello,

    Please see attached.

    Via macro, I am trying to establish where there is a gap in numbers, signified by a "-". The 2 cases of this are E3 and E5. Note that B7 isn't gap because it is the first numer in the sequence. Nor is L6, as it is the last.

    I'd be grateful for some code to generate the TRUE and FALSE values in column A.

    Thanks in advance.
    Attached Files Attached Files
    Last edited by bd528; 01-24-2011 at 12:34 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Try in A2

    =IF(COUNTIF(C2:K2,"-")<>0,TRUE,FALSE)

    Drag/Fill Down

    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Finding gaps within rows of numbers

    In A2:
    PHP Code: 
    =countif(C2:K2,"-")>
    Last edited by snb; 01-23-2011 at 01:21 PM.



  4. #4
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Thanks for the replies. For both cases, I cant figure out how to use the code within a macro. Can someone explain how it should be formatted/coded?

    Thanks again.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Finding gaps within rows of numbers

    Hello bd528,

    The attached workbook has the formulas entered into column "A".
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Thanks for your reply.

    What I require is a macro that adds the code to insert that code into the sheet in cells A10:A15. Its doing this that I'm having trouble with.

    Thanks.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Finding gaps within rows of numbers

    Hello bd528,

    You lost me. Do you want a macro that will insert the formulas into these cells?

  8. #8
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Quote Originally Posted by Leith Ross View Post
    Hello bd528,

    You lost me. Do you want a macro that will insert the formulas into these cells?
    Yes, to insert the formula.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Finding gaps within rows of numbers

    Hello bd528,

    Will the range start with "A1" and continue down to the last entry in column "A"?
    How do you want the macro to be run: button, shortcut keys, both?

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Finding gaps within rows of numbers

    this is your macro:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Yes, it will start at A1. I have defined the last row as "masterlastrow" elsewhere in the macro. This part of the code is about half way through the macro, so wont need executing seperately.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Try this
    Please Login or Register  to view this content.

    Assuming your data begins in B1 and Column A is free to use, "MasterLastRow" can be from your call.

    Hope this helps

  13. #13
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Quote Originally Posted by Marcol View Post
    Try this
    Please Login or Register  to view this content.

    Assuming your data begins in B1 and Column A is free to use, "MasterLastRow" can be from your call.

    Hope this helps
    That piece of code worked perfectly thanks.

    Unfortunately, after applying it to my actual spreadsheet, it turns out I didn't explain my problem thoroughly.

    Please see attached.

    As per the attached, there can be many "-" per row, and not a "gap", as in row 8 - so this is FALSE. Row 3 has many "-" and also a gap at AD, so it's value in column J is TRUE.
    Attached Files Attached Files

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Try this with your new sample sheet
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Quote Originally Posted by snb View Post
    this is your macro:

    Please Login or Register  to view this content.
    Sorry, I missed your post.

    I tried changing your code to suit the file I attached a few posts up. This is what I came up with :-

    Please Login or Register  to view this content.
    I think I must have written it wrong, as each result is coming up TRUE. Any ideas what I'm doing wrong. Its tricky to work out as the formula isn't displayed in the cell, just the result.

    Thanks.

  16. #16
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Quote Originally Posted by Marcol View Post
    Try this with your new sample sheet
    Please Login or Register  to view this content.
    This works pretty well. However I added a value to AC18, re-ran the macro, and it still came through as FALSE. (I copied the value from AF18 to AC18). Any thoughts?

  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Please don't quote whole posts in your replies, the Moderators don't like it..
    Only quote a part of the post if it is really needed for clarity

    Try this
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Marcol; 01-24-2011 at 09:45 AM. Reason: Changed code to better explain and make more versatile

  18. #18
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Marcol, I think we're nearly there. I added a little extra data (attached). For some reason, the results on rows 25 & 25 are incorrect??
    Attached Files Attached Files

  19. #19
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Okay, try this
    Please Login or Register  to view this content.
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    12-31-2008
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    149

    Re: Finding gaps within rows of numbers

    Marcol, this now works perfectly. Thanks for the time spent on this.

    I'll make sure I read through your code and learn what's going on.

    Thanks again.

  21. #21
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Finding gaps within rows of numbers

    Happy to have helped.

+ 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