+ Reply to Thread
Results 1 to 21 of 21

Counting letters and numbers separately in a single cell

  1. #1
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Counting letters and numbers separately in a single cell

    I would like to create a VBA script/module for Microsoft Excel to do the following.

    Identify if the cells in said column meet the two sequences below and highlight the cells Red that do not meet the sequence and highlight the cells green that do meet the sequence.

    3 letters 3 numbers (AAA111)
    1 number 2 letters 1 number 2 letters (1AA2BB)

    With the sequences above they might be separated by a comma and in different orders, example.

    AAA111
    1AA2BB
    AAA111,1AA2BB


    Please see below examples I gathered from around the internet. However it does not allow for commas and the first sequence 3 letters 3 numbers (AAA111).

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Counting letters and numbers separately in a single cell

    I think this macro might do what you want...
    Please Login or Register  to view this content.
    Note: It wasn't clear to me what column your data was in, so I guessed at Column F. If that was a wrong guess, then change the red F's to the correct column letter designation.

  3. #3
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    Thank you it works perfect!

    Is it possible to ignore case sensitivity? and if a blank entry make it highlight red as well?

  4. #4
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Counting letters and numbers separately in a single cell

    Quote Originally Posted by ss2012 View Post
    Is it possible to ignore case sensitivity? and if a blank entry make it highlight red as well?
    Give this macro a try...
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Counting letters and numbers separately in a single cell

    Out of interest...Trying to figure out Regular expressions...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  6. #6
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    Quote Originally Posted by Rick Rothstein View Post
    Give this macro a try...
    Please Login or Register  to view this content.
    Thank you

    Quote Originally Posted by sintek View Post
    Out of interest...Trying to figure out Regular expressions...
    Please Login or Register  to view this content.
    Complie error:
    User-defined type not defined

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Counting letters and numbers separately in a single cell

    Need to enable...
    Untitled.png

  8. #8
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    Hey, just came across some anomalies it seems if it has a 0 it doesn't the recognise the sequences

    Rick Rothstein see example that is highlighted green:
    20U8KK
    50G20E

    sintek see example that is highlighted green:
    0LQ123
    60F30Q
    Last edited by ss2012; 08-22-2019 at 10:31 PM.

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

    Re: Counting letters and numbers separately in a single cell

    Can you just upload a small sample workbook with data and the result that you want?

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

    Re: Counting letters and numbers separately in a single cell

    Perhaps
    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Counting letters and numbers separately in a single cell

    Quote Originally Posted by ss2012 View Post
    Hey, just came across some anomalies it seems if it has a 0 it doesn't the recognise the sequences

    Rick Rothstein see example that is highlighted green:
    20U8KK
    50G20E
    The pattern for the above are ##A#AA and ##A##A (where # means a digit and A means a letter). You said the "green" patterns were AAA### and #AA#AA. Since neither of your above examples meets the "green" patterns, I colored them red. Why was that wrong to do?

  12. #12
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    The correct sequence should be AAA### and #AA#AA

    However with #AA#AA if a 0 is in any of the A's it will highlight green but should be red because its not a Letter its a Digit. I hope that makes sense.


    Quote Originally Posted by jindon View Post
    Perhaps
    Please Login or Register  to view this content.
    I'll try this shortly.
    Last edited by AliGW; 08-27-2019 at 04:18 AM. Reason: Please don't quote unnecessarily!

  13. #13
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,463

    Re: Counting letters and numbers separately in a single cell

    It highlights red... not green... for me. Are you sure you have zeros where you indicate and not the letter O in upper case? Also check to make sure a trailing blank space (ASCII 32) or trailing non-breaking space (ASCII 160) did not accidentally get into the cell.
    Last edited by AliGW; 08-27-2019 at 04:18 AM. Reason: Please don't quote unnecessarily!

  14. #14
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Counting letters and numbers separately in a single cell

    sintek see example that is highlighted green:
    0LQ123
    60F30Q
    These and any other anomalies are highlighted red...
    As per jindon's suggestion...Upload a sample file with depicted expected results...

  15. #15
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    Thank you for the help I will be able to get the example document uploaded later tonight.

    Below is another example that shows green for me but the second entry should make it highlight red because of the 0 is not a A-za-z

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    I am unable to attach a document due to not enough posts.

    Cell A1 should be Red
    Cell A5 should be Red
    Cell A7 should be Red
    Cell A8 should be Red

    Please paste the following in cell A1
    Please Login or Register  to view this content.

  17. #17
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,220

    Re: Counting letters and numbers separately in a single cell

    You can attach a workbook with just ONE post!!!

    Unfortunately the attachment icon doesn't work at the moment (it hasn't worked for years, and despite our repeatedly asking the technical team who own the forum to fix it, they can't be bothered to do so), so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

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

    Re: Counting letters and numbers separately in a single cell

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    Quote Originally Posted by jindon View Post
    Please Login or Register  to view this content.
    Awesome! are you able to explain the regex?

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

    Re: Counting letters and numbers separately in a single cell

    Google with the keywords like

    VBA Regular Expression

    And you will get many web sites like https://analystcave.com/excel-regex-tutorial/

    Reg, your problem.

    You gave us the wrong conditions, number 0 Is NOT capital O...

  21. #21
    Registered User
    Join Date
    08-22-2019
    Location
    Australia
    MS-Off Ver
    365
    Posts
    9

    Re: Counting letters and numbers separately in a single cell

    thanks will suss it out.

    Also are you able to re-add as I am just having a bit of trouble incorporating it.

    Please Login or Register  to view this content.

+ 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. Incrementing Letter / Numbers / Letters in a single cell
    By Alan27 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-30-2017, 06:11 PM
  2. [SOLVED] arrange text and numbers separately in a single cell
    By nadimqaisar in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-25-2015, 06:43 PM
  3. Selecting letters/characters/numbers separately for a filter
    By WasWodge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2014, 09:12 PM
  4. Replies: 11
    Last Post: 10-16-2013, 10:21 PM
  5. [SOLVED] counting whole and decimal numbers separately
    By deth in forum Excel General
    Replies: 3
    Last Post: 06-05-2012, 12:24 PM
  6. [SOLVED] Counting Numbers within a Single Cell
    By VT_2000 in forum Excel General
    Replies: 5
    Last Post: 05-02-2012, 06:23 PM
  7. Counting Letters & numbers
    By MCPP in forum Excel General
    Replies: 0
    Last Post: 04-12-2011, 12:20 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