+ Reply to Thread
Results 1 to 16 of 16

Find missing numbers when total number known

  1. #1
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Find missing numbers when total number known

    Hi,
    I have many lists of number which are entered in the format in a single cell:

    1,2,3-6,7,10,11,12,13 all the way to 100, where 8 and 9 are missing
    1, 2, 3-9,6,7, 10-55, 67, 99,100

    Also there are 14 lines

    Line 1: 1,2,5,6,7, 10-66, 100
    Line 2: 8,9, 76-79
    Line 3: 81,82

    I have a cell that says what the count should be, lets call it 100
    How can I get back the missing numbers and find any duplicate numbers?

    Thanks
    JDI

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Find missing numbers when total number known

    Hi JDI,

    Is a "line" a row or column or a single cell?
    Can you supply a sample workbook to explain how you see the data and how you want your answer to appear?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    Line is a merged cell, line 1 is actually Y13:AI13, technically Y13 since its merged, line 2 is Y14:AI14 technically Y14 since its merged.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Find missing numbers when total number known

    Hi,

    Merged cells are a nightmare for doing formulas in Excel. We really need to see a sample of the data. I also don't understand how you want the results to be displayed.

  5. #5
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    Here is a sample, the row placement and the merged cells is an unchangeable issue I put the data is Y13-17 and the desired results/request next to it


    numberstrouble.xlsb

    Thanks
    JDI

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Find missing numbers when total number known

    Bump

    Hi JDI,

    Your data that has comma separated numbers with an occasional span of numbers (like 5-8) is a nightmare. I started writing a User Defined Function in VBA but need more incentive. Tell me this work has some value more than simply a fun game for you. Why do you get your data in this way? How important is needing to find missing and duplicate numbers? Can you get the data in a different way?

    Your last request to have all 4 number strings used for the missing and/or duplicate numbers makes this problem much harder also.

    Perhaps one of the good Excel Gurus will take a look at this and find an easy solution. For me, I need more reasons to work on this puzzle.

  7. #7
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    Hi Marvin, this is no joke, I am converting an old approach database. This is for my job and I just can't get a handle on it. There are hundreds of thousands of lines like this, the old users manually entered the data and the numbers are very very important. The data comes as is. I can not think of a way to separate it... We can leave out the last request. If it can't happen it can't happen.

    Thanks for your time.

  8. #8
    Registered User
    Join Date
    01-21-2014
    Location
    Greensboro, NC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find missing numbers when total number known

    I solved the first part where you can find the missing numbers. See attachment. In cell B16 put the row that contains your text (put 3 or 5 or 7 or 9 or 11) and the missing numbers will show up in cell C16.
    Finding the duplicates can be done in a similar way. The same is true with the latter part of your question but is more difficult to do.

    The best way to do this is a very simple macro that reads the string and separates the numbers (recognizes intervals and generates numbers within intervals). Then in the macro, sort the separated numbers and find missing/duplicate values.

    It takes about 20 minutes for me to write the macro. If you don't know Excel macros, then it is time to learn it!

    Good Luck!

    F
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    This works perfectly, I will attempt to use the vba to solve the other problems. In the meantime, any good book recommendations to learn VBA?

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find missing numbers when total number known

    I think that I have a solution for all the questions that you asked. I used a table filled in with the numbers that existed in each string. From that I determined the missing numbers.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  11. #11
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    Quote Originally Posted by newdoverman View Post
    I think that I have a solution for all the questions that you asked. I used a table filled in with the numbers that existed in each string. From that I determined the missing numbers.
    Hi newdoverman,
    That almost works except that 1,2,5-8,9 finds 1,2,5,8,9 when in fact 5-8 actually means 5,6,7,8. Also in the case of 1,3,20 it is finding 2 instead of 20. This has been my headache.

  12. #12
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Find missing numbers when total number known

    OK JDI,

    Find the attached with two User Defined Functions (UDF). One is to find what is missing and the other to find dups.

    You can use these like normal formulas. In your examples if you had "1,2,3-7,6-9,12,15" in cell H3 you would use the formulas like this:

    =MissingNums(H3) and after pressing enter it would show what numbers were missing. I have the defaults set to low of 1 and a max of 20 but you can change that.
    =DupNums(H3) would show the duplicate numbers in that cell.

    I have some optional parameters allowed in both of the above UDFs. If you want to specify a low of 5 and a high of 100 you would do it like this:
    =MissingNums(H3,5,100)

    Now if you want to do a bunch of strings all together, you will need to separate them with commas like this:

    =dupnums(G3& "," &G5& "," &G7& "," &G9,1,30)

    You will need to insure commas are places between each number and a real dash is between the span numbers.

    If something doesn't work correctly let me know by a private message and tell me what went wrong.

  13. #13
    Registered User
    Join Date
    01-21-2014
    Location
    Greensboro, NC, USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Find missing numbers when total number known

    JDI,

    I basically self-instructed myself to learn VBA. It is a powerful tool and you need to learn that to also write Excel functions pretty much similar to what MarvinP did, which is nice. Just Google Learn VBA and there should be many free online courses. I also used Excel Forum and Stackoverflow to learn issues with more complicated problems. This will open doors to a new Excel world.

    Good luck!

  14. #14
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    I think it has trouble recgonizing instances with no commas like 1-85, I understand the lower and upper arguments in A1, I though it wasn't working but I think it is this error instead.

    UDF MissingNums and DupNums with Optional low and high range.xlsm

  15. #15
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,165

    Re: Find missing numbers when total number known

    OK JDI,

    In the MissingNums UDF you still need to separate the separate strings by a &","&. See the example attached.
    In the DupNums I didn't handle a BLANK cell that was being added to the string.

    Give this next one a try and tell me if it works for you.

  16. #16
    Registered User
    Join Date
    10-02-2014
    Location
    Sylmar, Ca
    MS-Off Ver
    2011
    Posts
    44

    Re: Find missing numbers when total number known

    Everything is working perfectly, you are indeed a Guru.
    Thanks, very very much!

+ 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. How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  2. [SOLVED] How do I find a missing number in a sequence of numbers?
    By Peo Sjoblom in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  3. How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  4. How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. How do I find a missing number in a sequence of numbers?
    By Nash in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-11-2005, 12:05 AM

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