+ Reply to Thread
Results 1 to 10 of 10

Formula to determine range between two columns of numbers (by row)

  1. #1
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Formula to determine range between two columns of numbers (by row)

    Dear Excel Forum users/Experts,

    I have a problem, which I have spent many hours trying to resolve. Not being particularly MS Excel 'savvy', I'm getting nowhere fast! I'm therefore attempting to swallow my pride and ask for help!

    I have two columns (A and B) each contain thousands of rows of figures. Sample extract shown below:-

    Column A Column B
    49270000 49289999
    49350000 49409999
    49450000 49499999
    49690000 49809999
    49840000 49859999
    50260000 50299999
    50350000 50649999

    How do I get MS Excel to work out the variation between the numbers on each row (placing the results in another column), but to the minumum number of digits to satisfy all numbers within the 'range'?

    Using the first row of figures as an example:

    Column A Column B Column C
    49270000 49289999 4927, 4928

    The two numbers in Columns C represent the complete range of numbers between the two. For the second row the results would be:-

    Column A Column B Column C
    49350000 49409999 4935,4936,4937,4938,4939,4940

    Hope this makes sense.

    Instead of the results showing as csv in a single cell on the same row, I would prefer them to appear in a list in Column C (one under the other), with the results of the next rows calculation being appended to the list (and so on for all the entries in Columns A & B).

    I've attached a sample of the spreadsheet to allow you to see what I'm up against.

    Thanks

    Michael
    Attached Files Attached Files
    Last edited by mike.greene; 10-21-2012 at 08:04 PM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula to determine range between two columns of numbers (by row)

    Is this a restatement of your problem.
    "Given two numbers, a and b, list all the integers between a/10000 and b/10000, inclusive, in a comma delimited string."

    Do you want a formula solution or is VBA acceptable?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula to determine range between two columns of numbers (by row)

    it looks like you are just interested in using the 1st 4 numbers?

    maybe in your sample workbook, you could show what your expected outcome would be?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula to determine range between two columns of numbers (by row)

    You might find this UDF useful in formulas like
    =DelimitedIntegers(INT(A2/10000),INT(B2/10000))
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Formula to determine range between two columns of numbers (by row)

    Hi Mike,

    Thanks you for taking the time to respond

    Unfortunately the restatement is not wholly accurate. Not all the numbers in column A end in 0000. Column A values can end with any number of zeros ranging from anything from six to two zeros.

    To better clarify this I have added there expected results to the rows number 2 to 6 into Column C. I have coloured the range start and end of each row (ie Column A and B) a particular colour and also displayed the results for that particular row in column C (which I have kept the same colour to keep the tie in easy to follow).

    As you can see, the results of each new row are appended to the results of the previous rows results.

    Please let me know I have succeeding in clarifying the requirement (or instead made it more confusing).

    A VBA solution would be great, but really, either is fine (beggars can't be choosers), what ever is most convenient for you.


    Regards


    Mike
    Attached Files Attached Files
    Last edited by mike.greene; 10-22-2012 at 05:03 PM. Reason: correction!

  6. #6
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Formula to determine range between two columns of numbers (by row)

    Hi FDibbins,

    Again, thank you for taking time to respond

    I have responded to Mikerickson's post to which I attached the same spreadsheet with examples of output.

    Rather than repost the same spreadsheet again here (and using up valuable server space unnecessarily), could I ask you to look at this and see whether this sheds any more light on the subject for you (or anyone else who has offered to help).

    Thanks and regards

    Mike

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula to determine range between two columns of numbers (by row)

    Use the formula
    =DelimitedIntegers(A1/10^(9-MAX(SIGN(MOD(A1/10^{0,1,2,3,4,5,6,7,8,9,10},1))*{10,9,8,7,6,5,4,3,2,1,0})), INT(B1/10^(9-MAX(SIGN(MOD(A1/10^{0,1,2,3,4,5,6,7,8,9,10},1))*{10,9,8,7,6,5,4,3,2,1,0}))))

  8. #8
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Formula to determine range between two columns of numbers (by row)

    Quote Originally Posted by mikerickson View Post
    Use the formula
    =DelimitedIntegers(A1/10^(9-MAX(SIGN(MOD(A1/10^{0,1,2,3,4,5,6,7,8,9,10},1))*{10,9,8,7,6,5,4,3,2,1,0})), INT(B1/10^(9-MAX(SIGN(MOD(A1/10^{0,1,2,3,4,5,6,7,8,9,10},1))*{10,9,8,7,6,5,4,3,2,1,0}))))
    Hi Mike. Thank you for the formula. I'm having a little trouble knowing how and where to use it (forgive my ignorance).

    I've pasted the formula into an adjacent cell (column C), but I just get #NAME? showing in the cell. What am I doing wrong?

    Regards

    Michael
    Last edited by mike.greene; 10-23-2012 at 07:35 PM. Reason: correction

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Formula to determine range between two columns of numbers (by row)

    It has to be used with the UDF that I posted. The UDF should go in a normal code module.

  10. #10
    Registered User
    Join Date
    03-08-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Formula to determine range between two columns of numbers (by row)

    Hi Mike,

    I have tried your solution but, unfortunately, the results are not as expected. After I added the UDF to a code module and pasted the other formula into column C for row 2 the result was displayed as 50112. The actual results I was expect were 5011200 and 5011201, which is represents all the values between 50112000000 and 501120119999 (to the minimum number of digits to allow distinction between the two).

    Examples are shown in the attached spread sheet which is colour coded.

    Regards,

    Michael
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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