+ Reply to Thread
Results 1 to 15 of 15

Search for 3 digit number in a four digit number

  1. #1
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Search for 3 digit number in a four digit number

    Hi everyone,

    Can anyone please create a VBA code to search a 3 digit number in many four digit numbers and count how many that are there? Let me explain more descriptively, in my worksheet, there are many 4 digit numbers, and I want to know how much times a certain 3 digit number appeared in my worksheet. In 1234, there is, 123,124,134,234, right? Okay, so if I want to search for like a 234 in my worksheet, the computer should recognize 1234, or 4321 or 4123 or any number that have 234(in any order like 432,342, and so on) and count how many are there. Please help. Here is one small part of my worksheet.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search for 3 digit number in a four digit number

    Based on an User Defined Function I created for an OP in this thread, I created a slight variation for you.

    Please Login or Register  to view this content.

    This is a UDF, you install it in a standard code module, then you use it in a cell like any other function. Here is the formula how you would put it in M12:

    =CountPER($A$1:$J$6, 4,3,4)

    The first parameter is the range of cells to search.
    The second parameter is a list of numbers that make up your permutations. They can be in any order, as many as you wish.

    The function will return a count of how many cells contain ALL the numbers you've listed.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Re: Search for 3 digit number in a four digit number

    Hi Jbeaucaire,

    I can't seem to make it work, can you please apply it to the attached file in post 1, and attached it for me, please? Thank you.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for 3 digit number in a four digit number

    Don't understand why "4054" in Yellow counts for "434".
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Search for 3 digit number in a four digit number

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Search for 3 digit number in a four digit number

    Quote Originally Posted by Jerry HKA View Post
    Hi everyone,

    Can anyone please create a VBA code to search a 3 digit number in many four digit numbers and count how many that are there? Let me explain more descriptively, in my worksheet, there are many 4 digit numbers, and I want to know how much times a certain 3 digit number appeared in my worksheet. In 1234, there is, 123,124,134,234, right? Okay, so if I want to search for like a 234 in my worksheet, the computer should recognize 1234, or 4321 or 4123 or any number that have 234(in any order like 432,342, and so on) and count how many are there. Please help. Here is one small part of my worksheet.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Re: Search for 3 digit number in a four digit number

    Sorry, it was my mistake that the 4504 was highlighted. It shouldn't be.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for 3 digit number in a four digit number

    Quote Originally Posted by Jerry HKA View Post
    Sorry, it was my mistake that the 4504 was highlighted. It shouldn't be.
    Is it working or not?

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Search for 3 digit number in a four digit number

    Here is your workbook back with the UDF from post #2 already installed.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Search for 3 digit number in a four digit number


  11. #11
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Re: Search for 3 digit number in a four digit number

    To Sa DQ,
    I can't seem to make it work. Can you apply it to the attached in post 1. Thank you.

    To Jindon,
    Why is it only searching for 434 and 663, if it is not the result you got, can you approach the code and make it to search the worksheet, and arrange the numbers from most appeared, to least appeared. Thank you.

    To Jbeaucaire,
    Can you make the code help me search for many numbers at once, that will help me save time, pleas do try. Thank you

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for 3 digit number in a four digit number

    Quote Originally Posted by Jerry HKA View Post
    To Jindon,
    Why is it only searching for 434 and 663, if it is not the result you got, can you approach the code and make it to search the worksheet, and arrange the numbers from most appeared, to least appeared. Thank you.
    I don't understand what you are talking about.
    I wrote the code according to your sample file.

    What is your question then???

  13. #13
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Re: Search for 3 digit number in a four digit number

    I'm terribly sorry, Jindon,

    Your code is only searching for 434 and 663, but I don't only want to find those numbers, there are million of numbers wanted from me. But I only gave the two numbers as an example of the desired result. Please disregards the other written in the post for you.

    Or is it my fault of not knowing how to use your code properly, if so, please educate me of what to do.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for 3 digit number in a four digit number

    Quote Originally Posted by Jerry HKA View Post
    I'm terribly sorry, Jindon,

    Your code is only searching for 434 and 663, but I don't only want to find those numbers, there are million of numbers wanted from me. But I only gave the two numbers as an example of the desired result. Please disregards the other written in the post for you.
    Where are they?

  15. #15
    Forum Contributor Jerry HKA's Avatar
    Join Date
    09-25-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    126

    Re: Search for 3 digit number in a four digit number

    Okay, I tanhk you Jindon for helping me out here. I will be needing your help in the future. Thank you, Jbeaucaire, for your help. I really respect you. Thank you for all.

+ 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