+ Reply to Thread
Results 1 to 8 of 8

How to filter numbers by first digit ?

  1. #1
    Registered User
    Join Date
    06-08-2012
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2003
    Posts
    50

    How to filter numbers by first digit ?

    Hello guys,

    I have a table with many rows (over 10000) and I would like to filter all cells by the first digit of a column, let say C.
    This column has different numbers and simply I don't know how to filter them so that to keep only those numbers which start with 9. Of course, I would prefer to avoid any indirect method (looping, ordering + finding first and last relevant row, and so on) and to use the common AutoFilter feature, which is simpler and fast.
    Basically, the column that should be filtered is like below:
    Please Login or Register  to view this content.
    Taking into account that I should get something like
    Please Login or Register  to view this content.
    are there any way (at code level) to turn AutoFilter method to advantage ?
    Thank you in advance.

    Daniel

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How to filter numbers by first digit ?

    Hi Daniel,

    I would suggest you to use left or mid function to obtain the first digit and then you can filter / sort them easily.. thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    06-08-2012
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2003
    Posts
    50

    Re: How to filter numbers by first digit ?

    Hello Dilipandey,

    Thank you for your quick response. As we know, left or mid function involves a huge looping through each row of the sheet....If I would like after that to evaluate other digit, I consider this would not be a solution for saving time.
    Thank you for your interests in this issue.

  4. #4
    Forum Contributor thameem127's Avatar
    Join Date
    04-06-2012
    Location
    Jeddah,Saudi Arabia
    MS-Off Ver
    Excel 2003,Excel 2007
    Posts
    321

    Re: How to filter numbers by first digit ?

    Here it is. Check this attachment extract 9 macro.xlsm
    Thanks

    Thameem
    Last edited by thameem127; 09-21-2012 at 04:57 AM.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to filter numbers by first digit ?

    hi nemo66ro, option, please check attachment, select starting digit to filter list and press Run button
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-08-2012
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2003
    Posts
    50

    Re: How to filter numbers by first digit ?

    Hello guys,
    Both macro succeed to extract the numbers by first digit. However, the second seems to be more interesting as long as I work with arrays. I have some doubts that thameem127's approach could load the results in an array directly (as I know we have to declare a specific header for columns so that I think it is more suitable for calculations on sheet).
    Please Login or Register  to view this content.
    Regarding to the watersev code my issue is this is less readable...For example, how could I understand the code line below ?
    Please Login or Register  to view this content.
    It seems we have no less than 6 functions involved in one row...Watersev, do you think is possible to make this line more readable ? I appreciate your help this solving my issue but in the same time I would like learn something. Thank you in advance.

    Daniel

  7. #7
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to filter numbers by first digit ?

    that's an alternative to filter usage, you can split that line to:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-08-2012
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2003
    Posts
    50

    Re: How to filter numbers by first digit ?

    Hello everybody,

    I have searched online a solution to this issue and it is first time when I find one. Thanks to watersev I think many users will be able to go beyond an excel limitation: respectively, to use the Autofilter property "begins with" not just for text format data but for numbers too. Because I have considered this kind of filtering could be very useful in many cases, I have written a function so that to make entire solution more intelligible for everyone:
    Please Login or Register  to view this content.
    In the code lines above I have modified str1 = "|#" with str1 = "#" because in the splitting function I had getting
    an inconvenient position of the first value...
    Five globes for this solving, watersev. Many thanks.

    Daniel

+ 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