1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Excel Macro - Highlight Certain Cells

Discussion in 'Business Applications' started by computerman29642, Jun 17, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    I know this is probably very simple, and I am going to hit myself once the answer is found, but I cannot seem to think of the solution for the question below.

    I need to highlight all the cells in a column that does not contain a zero. How would I go about doing this with code?
     
  2. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    I was able to come up with this code:

    Range("C2:C678").FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
    Formula1:="=0"
    Range("C2:C678").FormatConditions(1).Interior.PatternColorIndex = xlAutomatic
    Range("C2:C678").FormatConditions(1).Interior.ThemeColor = xlThemeColorAccent1
    Range("C2:C678").FormatConditions(1).Interior.TintAndShade = 0.799981688894314

    Is there a better way to do this?
     
  3. slurpee55

    slurpee55

    Joined:
    Oct 20, 2004
    Messages:
    7,837
    Would the cells with a 0 only contain that figure (as your code suggests)? If so, why not just use conditional formatting?
     
  4. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    The cells will not always be a 0. The reason to have this done through code is that the original document is generated. I am creating a code that will apply to all workbooks that I can click a button when I generate one of these documents.
     
  5. slurpee55

    slurpee55

    Joined:
    Oct 20, 2004
    Messages:
    7,837
    Well, this would work in an another column (assuming your data is in A), but really it isn't what you want, I am sure. ;)
    =IF(ISERROR(SEARCH(0,A1,1)),"NO","YES")
     
  6. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Slupee, I will take a look at the code you have procide. Thanks. :)

    The code I pasted in post #2 actually works, I was just wondering if there was a better way.
     
  7. slurpee55

    slurpee55

    Joined:
    Oct 20, 2004
    Messages:
    7,837
    Darned if I know! Where are bomb, rollin, zack, etc. today anyway?? ;)
     
  8. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    LOL....That is a very good question. (y)
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/835982

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice