+ Reply to Thread
Results 1 to 4 of 4

Cell references error with recorded Conditional Formatting (Formula) macro

  1. #1
    Registered User
    Join Date
    12-08-2011
    Location
    Newfoundland, Canada
    MS-Off Ver
    Excel 2013
    Posts
    10

    Cell references error with recorded Conditional Formatting (Formula) macro

    I need to apply Conditional Formatting using a formula =$D3<>$D2. As I record the macro (see below), the Conditional Formatting works fine. But when I run the macro, and look at the Conditional Formatting rule, is shows different row references =$D5<>$D4 in the formula and formatting doesn't get applied correctly.

    What's going on?

    (Note that cell A3 is the top left cell in the current region)
    Please Login or Register  to view this content.
    Last edited by JosephP; 11-23-2012 at 09:56 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cell references error with recorded Conditional Formatting (Formula) macro

    try selecting A3 at the start of the code
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    12-08-2011
    Location
    Newfoundland, Canada
    MS-Off Ver
    Excel 2013
    Posts
    10

    Re: Cell references error with recorded Conditional Formatting (Formula) macro

    Thanks Joseph. Such a simple (but not obvious) solution.

    As a followup, with the next part of my macro, I'm trying to add a second Conditional Format =$D3=$D2 to a subset of the same range Range("A3").CurrentRegion.Resize(, 9). So, the first CF adds a top border to the entire row (12 columns) when the invoice # in column D is not equal to the cell above and the 2nd CF uses white font to hide the values in only the first 9 columns when the invoice # in column D is equal to the cell above.

    Here's the code for both conditions. The code in red is the second CF that I can't get to work.

    When I run the macro and look at the second CF, it says NO FORMAT SET.

    I'm guessing there is something simple/stupid that I'm missing.


    'Conditional Format rows with top border if Invoice # is different than cell above
    Range("A3").CurrentRegion.Select
    With Selection
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$D3<>$D2"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    .FormatConditions(1).Borders(xlTop).LineStyle = xlContinuous
    .FormatConditions(1).StopIfTrue = False
    End With

    'Conditional Format cells with white fond (i.e. hide data) if Invoice # is same as cell above
    Range("A3").CurrentRegion.Resize(, 9).Select
    With Selection
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$D2=$D3"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Font
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
    End With


    In the second CF, I tried changing FormatConditions(.FormatConditions.Count) to FormatConditions(2) and FormatConditions(.FormatConditions.Count) but it didn't make any difference.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Cell references error with recorded Conditional Formatting (Formula) macro

    have you tried setting the formatting (for condition 2) before you run the setfirstpriority line?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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