+ Reply to Thread
Results 1 to 8 of 8

Formula for getting the digit count between two numbers?

  1. #1
    Registered User
    Join Date
    08-02-2017
    Location
    Home
    MS-Off Ver
    Excel 2010
    Posts
    8

    Formula for getting the digit count between two numbers?

    Hi, I am mathematically dense so I thought I would post this here. I was wondering if there was a formula where I can input two numbers in separate cells and calculate how many individual digits are within that numerical sequence.

    For example, I was trying to do a puzzle and the solution was that there were 1128 digits/characters/integers between (and inclusive of) 1 and 412. In the puzzle the numbers of digits were given first and the person had to find out the answer of 412.

    I would have loved to have solved it myself with pen and paper in the shortest way possible but like I mentioned before I am mathematically dense. Sometimes I use excel and play around with various functions and find the solution by accident but not this time.

    It would be handy to have a small little tool in Excel that I could play with in the future in case I should need to solve something like this again.

    If anyone knows of a formula I could use in Excel then that would be great but it would also be nice to know how to solve this on paper, too.

    Thanks for any help.

    Cheers,
    Paul
    (mix_mash)

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Formula for getting the digit count between two numbers?

    not clear
    please upload a workbook with data
    now
    =SUM(LEN(ROW(INDEX($A:$A,$A2):INDEX($A:$A,$B2)))-LEN(SUBSTITUTE(ROW(INDEX($A:$A,$A2):INDEX($A:$A,$B2)),{0,1,2,3,4,5,6,7,8,9},""))) as array formula
    Last edited by tim201110; 09-30-2017 at 09:26 AM.

  3. #3
    Valued Forum Contributor Root_'s Avatar
    Join Date
    07-29-2017
    Location
    _
    MS-Off Ver
    2010+
    Posts
    483

    Re: Formula for getting the digit count between two numbers?

    Quote Originally Posted by mix_mash View Post
    ... I was wondering if there was a formula where I can input two numbers in separate cells and calculate how many individual digits are within that numerical sequence...
    Here is a formula for any two numbers from the range of 0...999. Cell A1 houses the smaller one:

    =MAX(0,MIN(9,B1)+1-MAX(0,A1))+MAX(0,MIN(99,B1)+1-MAX(10,A1))*2+MAX(0,MIN(999,B1)+1-MAX(100,A1))*3

  4. #4
    Registered User
    Join Date
    08-02-2017
    Location
    Home
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Formula for getting the digit count between two numbers?

    Quote Originally Posted by Root_ View Post
    Here is a formula for any two numbers from the range of 0...999. Cell A1 houses the smaller one:

    =MAX(0,MIN(9,B1)+1-MAX(0,A1))+MAX(0,MIN(99,B1)+1-MAX(10,A1))*2+MAX(0,MIN(999,B1)+1-MAX(100,A1))*3
    Excellent! Thank you for that. It works nicely. I will study it and see if I can modify it just in case I need to go a step further and into the thousands.

    Much obliged.

    Cheers,
    Paul
    (mix_mash)

  5. #5
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,899

    Re: Formula for getting the digit count between two numbers?

    If A1 >0 and B1>0 ,try:

    =SUMPRODUCT(LEN(ROW(INDIRECT(A1&":"&B1))))

  6. #6
    Registered User
    Join Date
    08-02-2017
    Location
    Home
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Formula for getting the digit count between two numbers?

    Quote Originally Posted by Phuocam View Post
    If A1 >0 and B1>0 ,try:

    =SUMPRODUCT(LEN(ROW(INDIRECT(A1&":"&B1))))
    Wow, this is just as good but shorter.

    Thank you.

    Paul
    (mix_mash)

  7. #7
    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,271

    Re: Formula for getting the digit count between two numbers?

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    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.

  8. #8
    Registered User
    Join Date
    08-02-2017
    Location
    Home
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Formula for getting the digit count between two numbers?

    Quote Originally Posted by AliGW View Post
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    OK, sorry about that. I am new to the 'solved' aspect of posting up a new thread. I may forget to do this in the future so please forgive me for this in advance.

    Cheers,
    Paul
    (mix_mash)

+ 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. Bank Recon - How to convert 8 digit formatted check numbers to 6 digit
    By Quisp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-21-2017, 09:55 PM
  2. [SOLVED] Need to count only 6 digit numbers
    By Sekars in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 06-02-2017, 10:47 AM
  3. Macro to identify 3-digit and 4-digit numbers as valid dates
    By gojakie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-16-2015, 08:16 AM
  4. Extract 4 digit common numbers from 5 digit numbers
    By ameque in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-24-2013, 01:09 AM
  5. [SOLVED] macro to extract 9 digit numbers as well as alpha numberic 9 digit numbers from txt file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2012, 10:15 AM
  6. To count numbers with 4 digit/5 digit with given Range.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2012, 08:49 AM
  7. Formula does not work with 13 digit numbers
    By sonar in forum Excel Formulas & Functions
    Replies: 46
    Last Post: 09-06-2005, 09: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