+ Reply to Thread
Results 1 to 4 of 4

vba conditional formating

  1. #1
    Registered User
    Join Date
    12-10-2008
    Location
    portugal
    Posts
    24

    vba conditional formating

    hello

    i'm looking for a vba that change color of cell A1 based in a value on other cell

    what I have is that code but only change the colour of the cell based on value of the same cell



    lLow = 0
    lmed = 1
    lHigh = 2

    Set Rng = Range("a1")
    Rng.FormatConditions.Delete ' delete any pre-existing formatting

    ' add greater than condition
    With Rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & lHigh)
    .Interior.Color = rgbLimeGreen
    End With

    ' add middle condition
    With Rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & lmed)
    .Interior.Color = rgbGold
    End With

    ' add less than condition
    With Rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlEqual, Formula1:="=" & lLow)
    .Interior.Color = rgbRed
    End With

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba conditional formating

    Why are you re-inventing the wheel. Why not just use the standard conditional formatting functionality?

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    12-10-2008
    Location
    portugal
    Posts
    24

    Re: vba conditional formating

    the idea is not re-inventing the wheel.
    I don't have knowledge in this mater to know what is a wheel

    how can I change the color of a empty cell A1 based on change values of other cell ?

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: vba conditional formating

    Hi,

    Sorry but the idea IS reinventing the wheel. It's just that you don't appear to realise the wheel yet exists.

    The fact that you even mention VBA sort of implies that you have more than a basic working knowledge of Excel, else why would you even know VBA exists or even what it may do for you?

    So I'm somewhat surprised that you don't seem to have considered conditional formatting. Do you know what it is?

    Since we're into descriptive metaphors the first port of call in a storm isn't adjacent to a rocky submerged reef.

    To answer your Q. Use a Conditional format in A1 using the'Formula Is' option. e.g.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and set the format of A1 to whatever you want should A2 take the value '1'.

    You don't say what version of Excel you have (please add that to your profile since it helps us respond to questions), but if you have Excel 2007 or later you can have many conditional formats in a cell. With Excel 2003 you only have three available to you.

+ 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