+ Reply to Thread
Results 1 to 8 of 8

Highlight cells in a certain column that contain 2 numbers

  1. #1
    Registered User
    Join Date
    11-01-2006
    Location
    Whitstable, Kent, UK
    MS-Off Ver
    MS 365
    Posts
    20

    Highlight cells in a certain column that contain 2 numbers

    Hi all

    I'm looking to highlight any cells in a given column (Address Line 1) if the cell contains 2 numbers.

    Sample data:

    Address Line 1

    23 Ash Road
    12 Cedar Avenue
    Flat 2 14 Elm Street
    Flat 6

    In the above column, Flat 2 14 Elm Street would be highlighted with a green fill as it has 2 numbers in the cell.

    Any assistance is greatly appreciated.

    Kenneth

  2. #2
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Highlight cells in a certain column that contain 2 numbers

    Hello... I'm pretty sure it can be done easily... but couldn't find a way... so:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-01-2006
    Location
    Whitstable, Kent, UK
    MS-Off Ver
    MS 365
    Posts
    20

    Re: Highlight cells in a certain column that contain 2 numbers

    Hi

    Yes that worked for me. In the interest of learning and understanding what you did would you be so kind and give me a brief explanation of what's happening, please?

    Thanks

  4. #4
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Highlight cells in a certain column that contain 2 numbers

    @Kennethc

    Glad it works!

    The best way to understand the code is DEBUG it, pressing F8 and checking the how TmpValue changes on each line

    What I did is:

    Defined the Worksheet I'm going to check
    Defined the Range with the data I'm checking (A1:A last row with data)
    For each cell in this range i'm doing a loop, that does:
    Get the cell value and set it into "TmpValue"
    TmpValue replaces all letters, one by one, for ""
    so, the only thing remains are the numbers and space between numbers

    If InStr(TmpValue, " ") <> 0 Then

    InStr is like a Find Formula in VBA

    I'm trying to find " " (one space) in TmpValue... It'd only happen if there is a space between 2 or more numbers, cause I've used Trim before.
    the result 0 means it didn't find anything... so if it is different then 0, do the routine

    Hope it is clear... I'm brazilian and my english isn't very good

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

    Re: Highlight cells in a certain column that contain 2 numbers

    Select the range and run the code
    Please Login or Register  to view this content.
    Last edited by jindon; 02-04-2016 at 09:37 AM.

  6. #6
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Highlight cells in a certain column that contain 2 numbers

    Much better!!!
    Thanks jindon

  7. #7
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: Highlight cells in a certain column that contain 2 numbers

    By the way... Just made another way to do it, using SPLIT:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-01-2006
    Location
    Whitstable, Kent, UK
    MS-Off Ver
    MS 365
    Posts
    20

    Re: Highlight cells in a certain column that contain 2 numbers

    Hi Gatti

    How can I amend your code so that it will look on the active sheet for a particular column heading in row 1 called say, "Address1"?
    Your code worked brilliantly but only in column A of a sheet called MySheet. The data I need it to work on could be in any column letter but will always be called "Address1".

    I hope you don't mind me asking, thanks.

    Kenneth

+ 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. Replies: 4
    Last Post: 11-20-2015, 11:19 AM
  2. Highlight cells in a row containing certain numbers
    By excy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-13-2015, 10:14 AM
  3. Replies: 2
    Last Post: 08-04-2014, 08:57 AM
  4. [SOLVED] highlight duplicate reference numbers in column A
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 06-06-2014, 04:57 AM
  5. Replies: 2
    Last Post: 04-17-2014, 03:30 PM
  6. Highlight all prime numbers in column
    By bluecat2013 in forum Excel General
    Replies: 3
    Last Post: 02-21-2014, 01:19 PM
  7. [SOLVED] Highlight Cells across columns containing several userdefined numbers/strings
    By dannyjoer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-26-2013, 05:10 AM

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