+ Reply to Thread
Results 1 to 2 of 2

Conditional Formatting Macros

  1. #1
    Registered User
    Join Date
    11-21-2011
    Location
    NYC
    MS-Off Ver
    2007
    Posts
    2

    Conditional Formatting Macros

    Hello All,

    This is my first post and I should mention that I am very new to VBA and am in a jam. So I have a spread sheet column A has a category (car names for example), column C has 1 value, column D has another value.

    So what I want to do is highlight the associated column A category if the absolute value of column c - column d is >= 5.

    I am able to so this for one row using conditional formatting but dont want to have to go through the steps of doing a conditional formart for every row. Is there anyway to create a conditional formatting macro that uses relative reference so for example there is data in row 999 i can hit a command ctrl + (a key) and it will highlight cell A999 if the abs of column c - column d is >=5?

    I have the following so far:

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+z
    '
    ActiveCell.FormulaR1C1 = "=ABS(RC[-3]-RC[-2])"
    Range("A2").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$F$2>=5"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    End Sub

    I want to be able to now then go to cell A3, hit ctrl+z and have it highlight cell A3 if the value abs value of column c - column d is >=5.

    Hopefully this makes sense?

    Thank you for your help.

    -Adam

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Conditional Formatting Macros

    Why do you want to do it individually for each row? Apply the conditional formatting condition for the entire column and it will highlight it whenever the condition is met. You do not need a macro for this.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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