+ Reply to Thread
Results 1 to 7 of 7

Need more than 2 conditions in Conditional Formatting

  1. #1
    Amy
    Guest

    Need more than 2 conditions in Conditional Formatting

    Is there a way to have more than just the 3 conditions in formatting or to
    work around it?

    I have a range of b4:b35 and I need to highlight cell different colors
    depending on cell value..
    If cell =0 then fill with red
    if cell =1 then fill with yellow
    if cell = 2 then fill with green
    if cell = 3 then fill with blue
    if cell =off then fill with grey

    so as of right now I need 5 conditions unless oen of you wonderful experts
    out there have an alternative solution for me....

    thank you in advance

  2. #2
    Bob Phillips
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    An example


    '-----------------------------------------------------------------
    Private Sub Worksheet_Change(ByVal Target As Range)
    '-----------------------------------------------------------------
    Const WS_RANGE As String = "B4:B35"

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target
    Select Case .Value
    Case 1: .Interior.ColorIndex = 3 'red
    Case 2: .Interior.ColorIndex = 6 'yellow
    Case 3: .Interior.ColorIndex = 5 'blue
    Case 4: .Interior.ColorIndex = 10 'green
    End Select
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Amy" <[email protected]> wrote in message
    news:[email protected]...
    > Is there a way to have more than just the 3 conditions in formatting or to
    > work around it?
    >
    > I have a range of b4:b35 and I need to highlight cell different colors
    > depending on cell value..
    > If cell =0 then fill with red
    > if cell =1 then fill with yellow
    > if cell = 2 then fill with green
    > if cell = 3 then fill with blue
    > if cell =off then fill with grey
    >
    > so as of right now I need 5 conditions unless oen of you wonderful experts
    > out there have an alternative solution for me....
    >
    > thank you in advance




  3. #3
    Amy
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    Thanks for trying to help Bob but apparently I am doing something incorrect.
    I went into the view code option of the sheet, pasted your code into it and
    edited it to fit my values amd added 2 additonal and nothing happens. I no
    nothing about writing code unfortunately and am at a loss. Any other thoughts?

    "Bob Phillips" wrote:

    > An example
    >
    >
    > '-----------------------------------------------------------------
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > '-----------------------------------------------------------------
    > Const WS_RANGE As String = "B4:B35"
    >
    > On Error GoTo ws_exit:
    > Application.EnableEvents = False
    > If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    > With Target
    > Select Case .Value
    > Case 1: .Interior.ColorIndex = 3 'red
    > Case 2: .Interior.ColorIndex = 6 'yellow
    > Case 3: .Interior.ColorIndex = 5 'blue
    > Case 4: .Interior.ColorIndex = 10 'green
    > End Select
    > End With
    > End If
    >
    > ws_exit:
    > Application.EnableEvents = True
    > End Sub
    >
    > 'This is worksheet event code, which means that it needs to be
    > 'placed in the appropriate worksheet code module, not a standard
    > 'code module. To do this, right-click on the sheet tab, select
    > 'the View Code option from the menu, and paste the code in.
    >
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "Amy" <[email protected]> wrote in message
    > news:[email protected]...
    > > Is there a way to have more than just the 3 conditions in formatting or to
    > > work around it?
    > >
    > > I have a range of b4:b35 and I need to highlight cell different colors
    > > depending on cell value..
    > > If cell =0 then fill with red
    > > if cell =1 then fill with yellow
    > > if cell = 2 then fill with green
    > > if cell = 3 then fill with blue
    > > if cell =off then fill with grey
    > >
    > > so as of right now I need 5 conditions unless oen of you wonderful experts
    > > out there have an alternative solution for me....
    > >
    > > thank you in advance

    >
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    Amy,

    can you show the code you entered?

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Amy" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks for trying to help Bob but apparently I am doing something

    incorrect.
    > I went into the view code option of the sheet, pasted your code into it

    and
    > edited it to fit my values amd added 2 additonal and nothing happens. I no
    > nothing about writing code unfortunately and am at a loss. Any other

    thoughts?
    >
    > "Bob Phillips" wrote:
    >
    > > An example
    > >
    > >
    > > '-----------------------------------------------------------------
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > '-----------------------------------------------------------------
    > > Const WS_RANGE As String = "B4:B35"
    > >
    > > On Error GoTo ws_exit:
    > > Application.EnableEvents = False
    > > If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    > > With Target
    > > Select Case .Value
    > > Case 1: .Interior.ColorIndex = 3 'red
    > > Case 2: .Interior.ColorIndex = 6 'yellow
    > > Case 3: .Interior.ColorIndex = 5 'blue
    > > Case 4: .Interior.ColorIndex = 10 'green
    > > End Select
    > > End With
    > > End If
    > >
    > > ws_exit:
    > > Application.EnableEvents = True
    > > End Sub
    > >
    > > 'This is worksheet event code, which means that it needs to be
    > > 'placed in the appropriate worksheet code module, not a standard
    > > 'code module. To do this, right-click on the sheet tab, select
    > > 'the View Code option from the menu, and paste the code in.
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "Amy" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Is there a way to have more than just the 3 conditions in formatting

    or to
    > > > work around it?
    > > >
    > > > I have a range of b4:b35 and I need to highlight cell different colors
    > > > depending on cell value..
    > > > If cell =0 then fill with red
    > > > if cell =1 then fill with yellow
    > > > if cell = 2 then fill with green
    > > > if cell = 3 then fill with blue
    > > > if cell =off then fill with grey
    > > >
    > > > so as of right now I need 5 conditions unless oen of you wonderful

    experts
    > > > out there have an alternative solution for me....
    > > >
    > > > thank you in advance

    > >
    > >
    > >




  5. #5
    David McRitchie
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    Hi Amy,
    I think you installed the code as you would an event macro, but it is not an event macro.
    Though you could install an event macro that applies to only one sheet, and
    would be automatically invoked, example in
    http://www.mvps.org/dmcritchie/excel/event.htm#case

    The code you got from Bob must go into a module and you might invoke
    it from Alt+F8 once installed.
    http://www.mvps.org/dmcritchie/excel....htm#havemacro

    ---
    HTH,
    David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
    My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
    Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

    "Amy" <[email protected]> wrote in message news:[email protected]...
    > Thanks for trying to help Bob but apparently I am doing something incorrect.
    > I went into the view code option of the sheet, pasted your code into it and
    > edited it to fit my values amd added 2 additonal and nothing happens. I no
    > nothing about writing code unfortunately and am at a loss. Any other thoughts?
    >
    > "Bob Phillips" wrote:
    >
    > > An example
    > >
    > >
    > > '-----------------------------------------------------------------
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > '-----------------------------------------------------------------
    > > Const WS_RANGE As String = "B4:B35"
    > >
    > > On Error GoTo ws_exit:
    > > Application.EnableEvents = False
    > > If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    > > With Target
    > > Select Case .Value
    > > Case 1: .Interior.ColorIndex = 3 'red
    > > Case 2: .Interior.ColorIndex = 6 'yellow
    > > Case 3: .Interior.ColorIndex = 5 'blue
    > > Case 4: .Interior.ColorIndex = 10 'green
    > > End Select
    > > End With
    > > End If
    > >
    > > ws_exit:
    > > Application.EnableEvents = True
    > > End Sub
    > >
    > > 'This is worksheet event code, which means that it needs to be
    > > 'placed in the appropriate worksheet code module, not a standard
    > > 'code module. To do this, right-click on the sheet tab, select
    > > 'the View Code option from the menu, and paste the code in.
    > >
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "Amy" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Is there a way to have more than just the 3 conditions in formatting or to
    > > > work around it?
    > > >
    > > > I have a range of b4:b35 and I need to highlight cell different colors
    > > > depending on cell value..
    > > > If cell =0 then fill with red
    > > > if cell =1 then fill with yellow
    > > > if cell = 2 then fill with green
    > > > if cell = 3 then fill with blue
    > > > if cell =off then fill with grey
    > > >
    > > > so as of right now I need 5 conditions unless oen of you wonderful experts
    > > > out there have an alternative solution for me....
    > > >
    > > > thank you in advance

    > >
    > >
    > >




  6. #6
    amy
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    Thank you both. Now that I "invoked" the code Bob gave me (with my data) it
    works. Thank you both for your help and follow through.

    "Bob Phillips" wrote:

    > Amy,
    >
    > can you show the code you entered?
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "Amy" <[email protected]> wrote in message
    > news:[email protected]...
    > > Thanks for trying to help Bob but apparently I am doing something

    > incorrect.
    > > I went into the view code option of the sheet, pasted your code into it

    > and
    > > edited it to fit my values amd added 2 additonal and nothing happens. I no
    > > nothing about writing code unfortunately and am at a loss. Any other

    > thoughts?
    > >
    > > "Bob Phillips" wrote:
    > >
    > > > An example
    > > >
    > > >
    > > > '-----------------------------------------------------------------
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > '-----------------------------------------------------------------
    > > > Const WS_RANGE As String = "B4:B35"
    > > >
    > > > On Error GoTo ws_exit:
    > > > Application.EnableEvents = False
    > > > If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    > > > With Target
    > > > Select Case .Value
    > > > Case 1: .Interior.ColorIndex = 3 'red
    > > > Case 2: .Interior.ColorIndex = 6 'yellow
    > > > Case 3: .Interior.ColorIndex = 5 'blue
    > > > Case 4: .Interior.ColorIndex = 10 'green
    > > > End Select
    > > > End With
    > > > End If
    > > >
    > > > ws_exit:
    > > > Application.EnableEvents = True
    > > > End Sub
    > > >
    > > > 'This is worksheet event code, which means that it needs to be
    > > > 'placed in the appropriate worksheet code module, not a standard
    > > > 'code module. To do this, right-click on the sheet tab, select
    > > > 'the View Code option from the menu, and paste the code in.
    > > >
    > > >
    > > > --
    > > > HTH
    > > >
    > > > Bob Phillips
    > > >
    > > > (remove nothere from email address if mailing direct)
    > > >
    > > > "Amy" <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > Is there a way to have more than just the 3 conditions in formatting

    > or to
    > > > > work around it?
    > > > >
    > > > > I have a range of b4:b35 and I need to highlight cell different colors
    > > > > depending on cell value..
    > > > > If cell =0 then fill with red
    > > > > if cell =1 then fill with yellow
    > > > > if cell = 2 then fill with green
    > > > > if cell = 3 then fill with blue
    > > > > if cell =off then fill with grey
    > > > >
    > > > > so as of right now I need 5 conditions unless oen of you wonderful

    > experts
    > > > > out there have an alternative solution for me....
    > > > >
    > > > > thank you in advance
    > > >
    > > >
    > > >

    >
    >
    >


  7. #7
    Bob Phillips
    Guest

    Re: Need more than 2 conditions in Conditional Formatting

    Well that's odd, because it was event code, and it should have worked as you
    entered the data. If the data already existed, you would have needed to edit
    it, even without actually changing it, to force the change event.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "amy" <[email protected]> wrote in message
    news:[email protected]...
    > Thank you both. Now that I "invoked" the code Bob gave me (with my data)

    it
    > works. Thank you both for your help and follow through.
    >
    > "Bob Phillips" wrote:
    >
    > > Amy,
    > >
    > > can you show the code you entered?
    > >
    > > --
    > > HTH
    > >
    > > Bob Phillips
    > >
    > > (remove nothere from email address if mailing direct)
    > >
    > > "Amy" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Thanks for trying to help Bob but apparently I am doing something

    > > incorrect.
    > > > I went into the view code option of the sheet, pasted your code into

    it
    > > and
    > > > edited it to fit my values amd added 2 additonal and nothing happens.

    I no
    > > > nothing about writing code unfortunately and am at a loss. Any other

    > > thoughts?
    > > >
    > > > "Bob Phillips" wrote:
    > > >
    > > > > An example
    > > > >
    > > > >
    > > > > '-----------------------------------------------------------------
    > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > '-----------------------------------------------------------------
    > > > > Const WS_RANGE As String = "B4:B35"
    > > > >
    > > > > On Error GoTo ws_exit:
    > > > > Application.EnableEvents = False
    > > > > If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    > > > > With Target
    > > > > Select Case .Value
    > > > > Case 1: .Interior.ColorIndex = 3 'red
    > > > > Case 2: .Interior.ColorIndex = 6 'yellow
    > > > > Case 3: .Interior.ColorIndex = 5 'blue
    > > > > Case 4: .Interior.ColorIndex = 10 'green
    > > > > End Select
    > > > > End With
    > > > > End If
    > > > >
    > > > > ws_exit:
    > > > > Application.EnableEvents = True
    > > > > End Sub
    > > > >
    > > > > 'This is worksheet event code, which means that it needs to be
    > > > > 'placed in the appropriate worksheet code module, not a standard
    > > > > 'code module. To do this, right-click on the sheet tab, select
    > > > > 'the View Code option from the menu, and paste the code in.
    > > > >
    > > > >
    > > > > --
    > > > > HTH
    > > > >
    > > > > Bob Phillips
    > > > >
    > > > > (remove nothere from email address if mailing direct)
    > > > >
    > > > > "Amy" <[email protected]> wrote in message
    > > > > news:[email protected]...
    > > > > > Is there a way to have more than just the 3 conditions in

    formatting
    > > or to
    > > > > > work around it?
    > > > > >
    > > > > > I have a range of b4:b35 and I need to highlight cell different

    colors
    > > > > > depending on cell value..
    > > > > > If cell =0 then fill with red
    > > > > > if cell =1 then fill with yellow
    > > > > > if cell = 2 then fill with green
    > > > > > if cell = 3 then fill with blue
    > > > > > if cell =off then fill with grey
    > > > > >
    > > > > > so as of right now I need 5 conditions unless oen of you wonderful

    > > experts
    > > > > > out there have an alternative solution for me....
    > > > > >
    > > > > > thank you in advance
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




+ 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