+ Reply to Thread
Results 1 to 12 of 12

VBA Conditional Formatting Formula1

  1. #1
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    VBA Conditional Formatting Formula1

    I have a range of cells that I want to compare to the cells immediately to the left (meaning I want to compare cell C5 to cell B5). If C5 is less than B5 I want it to turn red. I want to do this for a range of cells. C5:C20 and E5:E20 and G5:G20 etc. I have named this range MyRange. I originally thought I could use the OFFSET function but I get an error.

    Please Login or Register  to view this content.
    When I run this code it fails at the .Add line. I assume the problem is with the syntax of Range(MyRange).Offset(0,-1) but I don’t know. Anyone have any idea how to use VBA to set the conditional formatting using a formula by comparing the cell value to the cell to the left? A few notes… The reason I want to use VBA is that the user may select different formulas and the highlighting will change based on the selection (The users can select Percentage or Count or Variance). The vba is kicked off by an Event Procedure (Not sure this makes any difference but thought Id mention it)
    Thanks

  2. #2
    Forum Contributor
    Join Date
    10-10-2014
    Location
    New Jersey
    MS-Off Ver
    2010 & 2013
    Posts
    276

    Re: VBA Conditional Formatting Formula1

    Cant you just use conditional formatting? Use:

    Please Login or Register  to view this content.
    This will check if C1 is less than B1. If it is then you can format the cell to be red.

  3. #3
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    I cant reply. I am getting blocked by a firewall. It says I can not use HTML. I am not trying to. Anyone have any idea how I can reply to this post ?

  4. #4
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    Anyway that doesnt work ... Cant tell you why because the firewall wont let me.

  5. #5
    Forum Contributor
    Join Date
    10-10-2014
    Location
    New Jersey
    MS-Off Ver
    2010 & 2013
    Posts
    276

    Re: VBA Conditional Formatting Formula1

    It appears as though you were successful with replying?

  6. #6
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    Nope. it let me say that much but it wont let me type much. I have reached out to the Site Admins for asst. meanwhile I will try a little at a time. This is painful!

  7. #7
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    First it failed on C1 “Variable not defined”.

  8. #8
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    So I tried “C1” and got a Type Mismatch error.

  9. #9
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    then I tried putting the word Range in front of the Cell References like this ... Range("C1")

  10. #10
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    which ran, but all the cells were highlighted whether they were less than or not. AND when I checked the actual Conditional formatting on the cells the formula was Cell Value < FALSE. SO maybe I am misunderstanding your advise or I haven’t found the right combination. Because the range is complex I would love to be able to use offset or some form of it like Row(o)Column(-1) or R0C-1 or something.

  11. #11
    Forum Contributor
    Join Date
    10-10-2014
    Location
    New Jersey
    MS-Off Ver
    2010 & 2013
    Posts
    276

    Re: VBA Conditional Formatting Formula1

    Take a look at my example. If you select column C and choose conditional formatting > manage rules you will be able to see how it should be set up and work.

    Conditional formatting for scottc_00.xlsx

    EDIT: If that doesn't help, are you able to attach your workbook?

  12. #12
    Forum Contributor
    Join Date
    01-08-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    100

    Re: VBA Conditional Formatting Formula1

    Thanks Teblol for your help. Your solution
    Please Login or Register  to view this content.
    works but I dont really want to spin thru each cell individually. After looking into it some more, I fear I will have to consider each cell individually. However, with a little tweaking I was able to at lease not have to expressly tell it where to stop and start beyond identifying the range.
    Please Login or Register  to view this content.
    Thanks again for your help.

+ 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. [SOLVED] Looping through Formula1 and Formula2 of FormatConditions?
    By vaute in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2014, 07:13 PM
  2. [SOLVED] Cannot return value from FormatConditions.Item.Type/Formula1
    By Boffster in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-18-2014, 05:58 AM
  3. Get rid of Formula1 in a pivot table (Excel 2007)
    By jrussell in forum Excel General
    Replies: 0
    Last Post: 11-11-2008, 12:38 PM
  4. fill Formula1 with named range
    By Hammer_757 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2007, 04:52 PM
  5. FormatConditions(1).Formula1
    By Stefi in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-17-2006, 06:45 AM
  6. [SOLVED] Bug in .FormatConditions.Add Type:=xlExpression, Formula1:=cfExpression
    By Thief_ in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-18-2005, 10:06 PM
  7. Passing String to Formula1 Method in VB
    By Stew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2005, 10:06 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