+ Reply to Thread
Results 1 to 21 of 21

Conditional Formatting

  1. #1
    Rakesh Rampiar
    Guest

    Conditional Formatting

    Currently this fucntion only permits up to a maximum of three conditions. I
    find this a bit limiting. Will Microsoft consider amending this to five or
    more?

  2. #2
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Using event macros, it gets unlimited ...

    Carim

  3. #3
    Rithy Chhan
    Guest

    Re: Conditional Formatting

    Hello

    Can you show that macro?
    I also interest with this matter, because I have the same issue!

    Rithy
    "Carim" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Using event macros, it gets unlimited ...
    >
    > Carim
    >
    >
    > --
    > Carim
    > ------------------------------------------------------------------------
    > Carim's Profile:
    > http://www.excelforum.com/member.php...o&userid=33259
    > View this thread: http://www.excelforum.com/showthread...hreadid=531451
    >




  4. #4
    Dave Peterson
    Guest

    Re: Conditional Formatting

    The conditional formatting limit in the new version of excel that's scheduled to
    be released next year will be limited by your pc's memory.

    But until then you could use a worksheet event to look for changes.

    If the change is caused by the user typing something, you could use the
    worksheet_change event:

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim myRngToCheck As Range
    Dim myColorIndex As Long

    Set myRngToCheck = Me.Range("a1,b9,c13:c15")

    Select Case Target.Value
    Case Is = 1: myColorIndex = 3
    Case Is = 3: myColorIndex = 8
    Case Is = 5: myColorIndex = 10
    Case Else
    myColorIndex = xlNone
    End Select
    Target.Interior.ColorIndex = myColorIndex

    End Sub

    You can change the range to what you want and add as many rules as as much
    formatting as you want.

    You can read more about events at:
    Chip Pearson's site:
    http://www.cpearson.com/excel/events.htm

    David McRitchie's site:
    http://www.mvps.org/dmcritchie/excel/event.htm

    If you're new to macros, you may want to read David McRitchie's intro at:
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    Rakesh Rampiar wrote:
    >
    > Currently this fucntion only permits up to a maximum of three conditions. I
    > find this a bit limiting. Will Microsoft consider amending this to five or
    > more?


    --

    Dave Peterson

  5. #5
    LRodgers
    Guest

    Re: Conditional Formatting

    Could this be used in the following example:

    Cell A2 needs to be shaded "yellow" if A1 says "yes". Otherwise, A2 should
    be shaded gray.

    "Dave Peterson" wrote:

    > The conditional formatting limit in the new version of excel that's scheduled to
    > be released next year will be limited by your pc's memory.
    >
    > But until then you could use a worksheet event to look for changes.
    >
    > If the change is caused by the user typing something, you could use the
    > worksheet_change event:
    >
    > Option Explicit
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Dim myRngToCheck As Range
    > Dim myColorIndex As Long
    >
    > Set myRngToCheck = Me.Range("a1,b9,c13:c15")
    >
    > Select Case Target.Value
    > Case Is = 1: myColorIndex = 3
    > Case Is = 3: myColorIndex = 8
    > Case Is = 5: myColorIndex = 10
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Target.Interior.ColorIndex = myColorIndex
    >
    > End Sub
    >
    > You can change the range to what you want and add as many rules as as much
    > formatting as you want.
    >
    > You can read more about events at:
    > Chip Pearson's site:
    > http://www.cpearson.com/excel/events.htm
    >
    > David McRitchie's site:
    > http://www.mvps.org/dmcritchie/excel/event.htm
    >
    > If you're new to macros, you may want to read David McRitchie's intro at:
    > http://www.mvps.org/dmcritchie/excel/getstarted.htm
    >
    > Rakesh Rampiar wrote:
    > >
    > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > more?

    >
    > --
    >
    > Dave Peterson
    >


  6. #6
    Dave Peterson
    Guest

    Re: Conditional Formatting

    Maybe--it depends on how A1 changes.

    But in cases like this, using Format|Conditional Formatting would be easier.

    But if you want, this changes the fill color when A1 changes (by typing):

    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub

    If LCase(Target.Value) = "yes" Then
    Target.Offset(1, 0).Interior.ColorIndex = 6
    Else
    Target.Offset(1, 0).Interior.ColorIndex = 15
    End If

    End Sub

    Colors are specific to workbooks. 6 was a dark yellow and 15 was a grey for my
    workbook. You may want to record a macro when you change a test cell's color.

    LRodgers wrote:
    >
    > Could this be used in the following example:
    >
    > Cell A2 needs to be shaded "yellow" if A1 says "yes". Otherwise, A2 should
    > be shaded gray.
    >
    > "Dave Peterson" wrote:
    >
    > > The conditional formatting limit in the new version of excel that's scheduled to
    > > be released next year will be limited by your pc's memory.
    > >
    > > But until then you could use a worksheet event to look for changes.
    > >
    > > If the change is caused by the user typing something, you could use the
    > > worksheet_change event:
    > >
    > > Option Explicit
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > >
    > > Dim myRngToCheck As Range
    > > Dim myColorIndex As Long
    > >
    > > Set myRngToCheck = Me.Range("a1,b9,c13:c15")
    > >
    > > Select Case Target.Value
    > > Case Is = 1: myColorIndex = 3
    > > Case Is = 3: myColorIndex = 8
    > > Case Is = 5: myColorIndex = 10
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > Target.Interior.ColorIndex = myColorIndex
    > >
    > > End Sub
    > >
    > > You can change the range to what you want and add as many rules as as much
    > > formatting as you want.
    > >
    > > You can read more about events at:
    > > Chip Pearson's site:
    > > http://www.cpearson.com/excel/events.htm
    > >
    > > David McRitchie's site:
    > > http://www.mvps.org/dmcritchie/excel/event.htm
    > >
    > > If you're new to macros, you may want to read David McRitchie's intro at:
    > > http://www.mvps.org/dmcritchie/excel/getstarted.htm
    > >
    > > Rakesh Rampiar wrote:
    > > >
    > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > more?

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  7. #7
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    Hi Dave

    Thanks for the response. I am finding difficult to run this macro
    effectively. I copied it to PERSONAL.XLS and named it macro1. Typed the
    numbers as you suggested in the cells that you suggested and nothing happens?

    "Dave Peterson" wrote:

    > The conditional formatting limit in the new version of excel that's scheduled to
    > be released next year will be limited by your pc's memory.
    >
    > But until then you could use a worksheet event to look for changes.
    >
    > If the change is caused by the user typing something, you could use the
    > worksheet_change event:
    >
    > Option Explicit
    > Private Sub Worksheet_Change(ByVal Target As Range)
    >
    > Dim myRngToCheck As Range
    > Dim myColorIndex As Long
    >
    > Set myRngToCheck = Me.Range("a1,b9,c13:c15")
    >
    > Select Case Target.Value
    > Case Is = 1: myColorIndex = 3
    > Case Is = 3: myColorIndex = 8
    > Case Is = 5: myColorIndex = 10
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Target.Interior.ColorIndex = myColorIndex
    >
    > End Sub
    >
    > You can change the range to what you want and add as many rules as as much
    > formatting as you want.
    >
    > You can read more about events at:
    > Chip Pearson's site:
    > http://www.cpearson.com/excel/events.htm
    >
    > David McRitchie's site:
    > http://www.mvps.org/dmcritchie/excel/event.htm
    >
    > If you're new to macros, you may want to read David McRitchie's intro at:
    > http://www.mvps.org/dmcritchie/excel/getstarted.htm
    >
    > Rakesh Rampiar wrote:
    > >
    > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > more?

    >
    > --
    >
    > Dave Peterson
    >


  8. #8
    Rakesh Rampiar
    Guest

    RE: Conditional Formatting

    Hi Dave

    Thanks for the response. I've not used macros before. All I want to do is
    this:

    If cell is 1 colour Blue
    If cell is between 1.1 and 2 colour green
    If cell is between 2.1 and 3 colour Yellow
    If cell is between 3.1 and 4 colour Orange
    If cell is between 4.1 and 5 colour Red

    Would really appreciate your help on this.

    Regards

    Rakesh



    "Rakesh Rampiar" wrote:

    > Currently this fucntion only permits up to a maximum of three conditions. I
    > find this a bit limiting. Will Microsoft consider amending this to five or
    > more?


  9. #9
    JE McGimpsey
    Guest

    Re: Conditional Formatting

    If you're talking about font color, you can do it without macros:

    http://www.mcgimpsey.com/excel/conditional6.html

    If not, see

    http://www.mvps.org/dmcritchie/excel....htm#calculate

    for a Worksheet_Calculate() event macro that can handle multiple colors.



    In article <[email protected]>,
    Rakesh Rampiar <[email protected]> wrote:

    > Hi Dave
    >
    > Thanks for the response. I've not used macros before. All I want to do is
    > this:
    >
    > If cell is 1 colour Blue
    > If cell is between 1.1 and 2 colour green
    > If cell is between 2.1 and 3 colour Yellow
    > If cell is between 3.1 and 4 colour Orange
    > If cell is between 4.1 and 5 colour Red
    >
    > Would really appreciate your help on this.
    >
    > Regards
    >
    > Rakesh
    >
    >
    >
    > "Rakesh Rampiar" wrote:
    >
    > > Currently this fucntion only permits up to a maximum of three conditions.
    > > I
    > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > more?


  10. #10
    Dave Peterson
    Guest

    Re: Conditional Formatting

    This kind of code doesn't go in the personal.xls workbook.

    Right click on the worksheet tab that should have this behavior and select view
    code. Paste the code into that window.

    Make sure you review those links, too.

    Rakesh Rampiar wrote:
    >
    > Hi Dave
    >
    > Thanks for the response. I am finding difficult to run this macro
    > effectively. I copied it to PERSONAL.XLS and named it macro1. Typed the
    > numbers as you suggested in the cells that you suggested and nothing happens?
    >
    > "Dave Peterson" wrote:
    >
    > > The conditional formatting limit in the new version of excel that's scheduled to
    > > be released next year will be limited by your pc's memory.
    > >
    > > But until then you could use a worksheet event to look for changes.
    > >
    > > If the change is caused by the user typing something, you could use the
    > > worksheet_change event:
    > >
    > > Option Explicit
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > >
    > > Dim myRngToCheck As Range
    > > Dim myColorIndex As Long
    > >
    > > Set myRngToCheck = Me.Range("a1,b9,c13:c15")
    > >
    > > Select Case Target.Value
    > > Case Is = 1: myColorIndex = 3
    > > Case Is = 3: myColorIndex = 8
    > > Case Is = 5: myColorIndex = 10
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > Target.Interior.ColorIndex = myColorIndex
    > >
    > > End Sub
    > >
    > > You can change the range to what you want and add as many rules as as much
    > > formatting as you want.
    > >
    > > You can read more about events at:
    > > Chip Pearson's site:
    > > http://www.cpearson.com/excel/events.htm
    > >
    > > David McRitchie's site:
    > > http://www.mvps.org/dmcritchie/excel/event.htm
    > >
    > > If you're new to macros, you may want to read David McRitchie's intro at:
    > > http://www.mvps.org/dmcritchie/excel/getstarted.htm
    > >
    > > Rakesh Rampiar wrote:
    > > >
    > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > more?

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  11. #11
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    I am talking about cell colour.

    "JE McGimpsey" wrote:

    > If you're talking about font color, you can do it without macros:
    >
    > http://www.mcgimpsey.com/excel/conditional6.html
    >
    > If not, see
    >
    > http://www.mvps.org/dmcritchie/excel....htm#calculate
    >
    > for a Worksheet_Calculate() event macro that can handle multiple colors.
    >
    >
    >
    > In article <[email protected]>,
    > Rakesh Rampiar <[email protected]> wrote:
    >
    > > Hi Dave
    > >
    > > Thanks for the response. I've not used macros before. All I want to do is
    > > this:
    > >
    > > If cell is 1 colour Blue
    > > If cell is between 1.1 and 2 colour green
    > > If cell is between 2.1 and 3 colour Yellow
    > > If cell is between 3.1 and 4 colour Orange
    > > If cell is between 4.1 and 5 colour Red
    > >
    > > Would really appreciate your help on this.
    > >
    > > Regards
    > >
    > > Rakesh
    > >
    > >
    > >
    > > "Rakesh Rampiar" wrote:
    > >
    > > > Currently this fucntion only permits up to a maximum of three conditions.
    > > > I
    > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > more?

    >


  12. #12
    Rakesh Rampiar
    Guest

    RE: Conditional Formatting

    Dear Dave

    I managed to run the worksheet macro successfully. When I change the number
    on a worksheet with the macro it does automattically change the colour,
    however if that same worksheet has a link on from another worksheet in the
    same book and when that worksheet has been changed, the worksheet with the
    macro does not automatically change colour. I would have to press F2 on that
    cell for it to change colour. Is there any way around this.

    Regards

    Rakesh

    "Rakesh Rampiar" wrote:

    > Currently this fucntion only permits up to a maximum of three conditions. I
    > find this a bit limiting. Will Microsoft consider amending this to five or
    > more?


  13. #13
    Dave Peterson
    Guest

    Re: Conditional Formatting

    Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?

    If you are, make sure you have calculation set to automatic
    (tools|Options|calculation tab).



    Rakesh Rampiar wrote:
    >
    > Dear Dave
    >
    > I managed to run the worksheet macro successfully. When I change the number
    > on a worksheet with the macro it does automattically change the colour,
    > however if that same worksheet has a link on from another worksheet in the
    > same book and when that worksheet has been changed, the worksheet with the
    > macro does not automatically change colour. I would have to press F2 on that
    > cell for it to change colour. Is there any way around this.
    >
    > Regards
    >
    > Rakesh
    >
    > "Rakesh Rampiar" wrote:
    >
    > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > more?


    --

    Dave Peterson

  14. #14
    JE McGimpsey
    Guest

    Re: Conditional Formatting

    Then you can use my second suggestion...

    In article <[email protected]>,
    Rakesh Rampiar <[email protected]> wrote:

    > I am talking about cell colour.
    >
    > "JE McGimpsey" wrote:
    >
    > > If you're talking about font color, you can do it without macros:
    > >
    > > http://www.mcgimpsey.com/excel/conditional6.html
    > >
    > > If not, see
    > >
    > > http://www.mvps.org/dmcritchie/excel....htm#calculate


  15. #15
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    Hi Dave

    Yes (eventually), I am am using the worksheet_calculate event and checked
    that the calculation tab is on automatic (default), still no joy. I went
    into that website that McGimpsey suggested but because of my lack knowledge
    in VBA, could not find what I am looking for.

    Currently I am using this code: (as suggested by yourself)

    Private Sub Worksheet_Calculate()
    End Sub

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myRngToCheck As Range
    Dim myColorIndex As Long
    Set myRngToCheck = Me.Range("$a$1")
    Select Case Target.Value
    Case Is = 0: myColorIndex = 0 'White
    Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    Case Is = 2, Is < 2: myColorIndex = 9 'Green
    Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    Case Is = 5, Is < 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    Target.Interior.ColorIndex = myColorIndex

    End Sub

    Now the code works perfect when I type the actual figures on any cell but
    when there's a formula in a cell the colour of the cell does not change
    automatically, E.g.

    I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    sum(a1:b1)/2.
    When I typed 3 the cell colour changes and likewise when 4is typed, however
    cell C1 only changes if I press F2 on the cell and enter it.

    Please help.

    Regards

    Rakesh




    "Dave Peterson" wrote:

    > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    >
    > If you are, make sure you have calculation set to automatic
    > (tools|Options|calculation tab).
    >
    >
    >
    > Rakesh Rampiar wrote:
    > >
    > > Dear Dave
    > >
    > > I managed to run the worksheet macro successfully. When I change the number
    > > on a worksheet with the macro it does automattically change the colour,
    > > however if that same worksheet has a link on from another worksheet in the
    > > same book and when that worksheet has been changed, the worksheet with the
    > > macro does not automatically change colour. I would have to press F2 on that
    > > cell for it to change colour. Is there any way around this.
    > >
    > > Regards
    > >
    > > Rakesh
    > >
    > > "Rakesh Rampiar" wrote:
    > >
    > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > more?

    >
    > --
    >
    > Dave Peterson
    >


  16. #16
    Dave Peterson
    Guest

    Re: Conditional Formatting

    You are using the Worksheet_change event. Notice that there is no code in the
    worksheet_calculate procedure.

    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim myCell As Range
    Dim myColorIndex As Long
    Set myCell = Me.Range("$a$1")
    Select Case myCell.Value
    Case Is = 0: myColorIndex = 0 'White
    Case Is <= 1: myColorIndex = 22 'Blue
    Case Is <= 2: myColorIndex = 9 'Green
    Case Is <= 3: myColorIndex = 6 'Yellow
    Case Is <= 4: myColorIndex = 12 'Orange
    Case Is <= 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    myCell.Interior.ColorIndex = myColorIndex
    End Sub



    Rakesh Rampiar wrote:
    >
    > Hi Dave
    >
    > Yes (eventually), I am am using the worksheet_calculate event and checked
    > that the calculation tab is on automatic (default), still no joy. I went
    > into that website that McGimpsey suggested but because of my lack knowledge
    > in VBA, could not find what I am looking for.
    >
    > Currently I am using this code: (as suggested by yourself)
    >
    > Private Sub Worksheet_Calculate()
    > End Sub
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > Dim myRngToCheck As Range
    > Dim myColorIndex As Long
    > Set myRngToCheck = Me.Range("$a$1")
    > Select Case Target.Value
    > Case Is = 0: myColorIndex = 0 'White
    > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Target.Interior.ColorIndex = myColorIndex
    >
    > End Sub
    >
    > Now the code works perfect when I type the actual figures on any cell but
    > when there's a formula in a cell the colour of the cell does not change
    > automatically, E.g.
    >
    > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > sum(a1:b1)/2.
    > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > cell C1 only changes if I press F2 on the cell and enter it.
    >
    > Please help.
    >
    > Regards
    >
    > Rakesh
    >
    > "Dave Peterson" wrote:
    >
    > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > >
    > > If you are, make sure you have calculation set to automatic
    > > (tools|Options|calculation tab).
    > >
    > >
    > >
    > > Rakesh Rampiar wrote:
    > > >
    > > > Dear Dave
    > > >
    > > > I managed to run the worksheet macro successfully. When I change the number
    > > > on a worksheet with the macro it does automattically change the colour,
    > > > however if that same worksheet has a link on from another worksheet in the
    > > > same book and when that worksheet has been changed, the worksheet with the
    > > > macro does not automatically change colour. I would have to press F2 on that
    > > > cell for it to change colour. Is there any way around this.
    > > >
    > > > Regards
    > > >
    > > > Rakesh
    > > >
    > > > "Rakesh Rampiar" wrote:
    > > >
    > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > more?

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  17. #17
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    Hi Dave

    Thanks Dave. Below is how I posted it on excel, however, it now does not
    want to run at all. It gives me an error '13' Type Mismatch. Sorry to
    bother you.

    Regards

    Rakesh

    Option Explicit

    Private Sub Worksheet_Calculate()

    Dim myCell As Range
    Dim myColorIndex As Long

    Set myCell = Me.Range("$a$1")

    Select Case myCell.Value
    Case Is = 0: myColorIndex = 2 'White
    Case Is = 1, Is < 1: myColorIndex = 5 'Blue
    Case Is = 2, Is < 2: myColorIndex = 4 'Green
    Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    Case Is = 4, Is < 4: myColorIndex = 46 'Orange
    Case Is = 5, Is < 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    myCell.Interior.ColorIndex = myColorIndex

    End Sub


    "Dave Peterson" wrote:

    > You are using the Worksheet_change event. Notice that there is no code in the
    > worksheet_calculate procedure.
    >
    > Option Explicit
    > Private Sub Worksheet_Calculate()
    > Dim myCell As Range
    > Dim myColorIndex As Long
    > Set myCell = Me.Range("$a$1")
    > Select Case myCell.Value
    > Case Is = 0: myColorIndex = 0 'White
    > Case Is <= 1: myColorIndex = 22 'Blue
    > Case Is <= 2: myColorIndex = 9 'Green
    > Case Is <= 3: myColorIndex = 6 'Yellow
    > Case Is <= 4: myColorIndex = 12 'Orange
    > Case Is <= 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > myCell.Interior.ColorIndex = myColorIndex
    > End Sub
    >
    >
    >
    > Rakesh Rampiar wrote:
    > >
    > > Hi Dave
    > >
    > > Yes (eventually), I am am using the worksheet_calculate event and checked
    > > that the calculation tab is on automatic (default), still no joy. I went
    > > into that website that McGimpsey suggested but because of my lack knowledge
    > > in VBA, could not find what I am looking for.
    > >
    > > Currently I am using this code: (as suggested by yourself)
    > >
    > > Private Sub Worksheet_Calculate()
    > > End Sub
    > >
    > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > Dim myRngToCheck As Range
    > > Dim myColorIndex As Long
    > > Set myRngToCheck = Me.Range("$a$1")
    > > Select Case Target.Value
    > > Case Is = 0: myColorIndex = 0 'White
    > > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > Target.Interior.ColorIndex = myColorIndex
    > >
    > > End Sub
    > >
    > > Now the code works perfect when I type the actual figures on any cell but
    > > when there's a formula in a cell the colour of the cell does not change
    > > automatically, E.g.
    > >
    > > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > > sum(a1:b1)/2.
    > > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > > cell C1 only changes if I press F2 on the cell and enter it.
    > >
    > > Please help.
    > >
    > > Regards
    > >
    > > Rakesh
    > >
    > > "Dave Peterson" wrote:
    > >
    > > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > > >
    > > > If you are, make sure you have calculation set to automatic
    > > > (tools|Options|calculation tab).
    > > >
    > > >
    > > >
    > > > Rakesh Rampiar wrote:
    > > > >
    > > > > Dear Dave
    > > > >
    > > > > I managed to run the worksheet macro successfully. When I change the number
    > > > > on a worksheet with the macro it does automattically change the colour,
    > > > > however if that same worksheet has a link on from another worksheet in the
    > > > > same book and when that worksheet has been changed, the worksheet with the
    > > > > macro does not automatically change colour. I would have to press F2 on that
    > > > > cell for it to change colour. Is there any way around this.
    > > > >
    > > > > Regards
    > > > >
    > > > > Rakesh
    > > > >
    > > > > "Rakesh Rampiar" wrote:
    > > > >
    > > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > > more?
    > > >
    > > > --
    > > >
    > > > Dave Peterson
    > > >

    >
    > --
    >
    > Dave Peterson
    >


  18. #18
    Dave Peterson
    Guest

    Re: Conditional Formatting

    What's in A1?

    What version of excel are you using?

    Maybe...

    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim myCell As Range
    Dim myColorIndex As Long
    Set myCell = Me.Range("$a$1")
    If IsNumeric(myCell.Value) Then
    Select Case myCell.Value
    Case Is = 0: myColorIndex = 0 'White
    Case Is <= 1: myColorIndex = 5 'Blue
    Case Is <= 2: myColorIndex = 4 'Green
    Case Is <= 3: myColorIndex = 6 'Yellow
    Case Is <= 4: myColorIndex = 46 'Orange
    Case Is <= 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    Else
    myColorIndex = xlNone
    End If
    myCell.Interior.ColorIndex = myColorIndex
    End Sub

    This didn't cause any trouble, but...

    this line:
    Case Is = 2, Is < 2: myColorIndex = 4 'Green
    is the same as:
    Case Is <= 2: myColorIndex = 4 'Green

    I find the second one easier to read.

    Rakesh Rampiar wrote:
    >
    > Hi Dave
    >
    > Thanks Dave. Below is how I posted it on excel, however, it now does not
    > want to run at all. It gives me an error '13' Type Mismatch. Sorry to
    > bother you.
    >
    > Regards
    >
    > Rakesh
    >
    > Option Explicit
    >
    > Private Sub Worksheet_Calculate()
    >
    > Dim myCell As Range
    > Dim myColorIndex As Long
    >
    > Set myCell = Me.Range("$a$1")
    >
    > Select Case myCell.Value
    > Case Is = 0: myColorIndex = 2 'White
    > Case Is = 1, Is < 1: myColorIndex = 5 'Blue
    > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > Case Is = 4, Is < 4: myColorIndex = 46 'Orange
    > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > myCell.Interior.ColorIndex = myColorIndex
    >
    > End Sub
    >
    > "Dave Peterson" wrote:
    >
    > > You are using the Worksheet_change event. Notice that there is no code in the
    > > worksheet_calculate procedure.
    > >
    > > Option Explicit
    > > Private Sub Worksheet_Calculate()
    > > Dim myCell As Range
    > > Dim myColorIndex As Long
    > > Set myCell = Me.Range("$a$1")
    > > Select Case myCell.Value
    > > Case Is = 0: myColorIndex = 0 'White
    > > Case Is <= 1: myColorIndex = 22 'Blue
    > > Case Is <= 2: myColorIndex = 9 'Green
    > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > Case Is <= 4: myColorIndex = 12 'Orange
    > > Case Is <= 5: myColorIndex = 3 'Red
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > myCell.Interior.ColorIndex = myColorIndex
    > > End Sub
    > >
    > >
    > >
    > > Rakesh Rampiar wrote:
    > > >
    > > > Hi Dave
    > > >
    > > > Yes (eventually), I am am using the worksheet_calculate event and checked
    > > > that the calculation tab is on automatic (default), still no joy. I went
    > > > into that website that McGimpsey suggested but because of my lack knowledge
    > > > in VBA, could not find what I am looking for.
    > > >
    > > > Currently I am using this code: (as suggested by yourself)
    > > >
    > > > Private Sub Worksheet_Calculate()
    > > > End Sub
    > > >
    > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > Dim myRngToCheck As Range
    > > > Dim myColorIndex As Long
    > > > Set myRngToCheck = Me.Range("$a$1")
    > > > Select Case Target.Value
    > > > Case Is = 0: myColorIndex = 0 'White
    > > > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > > > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > Case Else
    > > > myColorIndex = xlNone
    > > > End Select
    > > > Target.Interior.ColorIndex = myColorIndex
    > > >
    > > > End Sub
    > > >
    > > > Now the code works perfect when I type the actual figures on any cell but
    > > > when there's a formula in a cell the colour of the cell does not change
    > > > automatically, E.g.
    > > >
    > > > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > > > sum(a1:b1)/2.
    > > > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > > > cell C1 only changes if I press F2 on the cell and enter it.
    > > >
    > > > Please help.
    > > >
    > > > Regards
    > > >
    > > > Rakesh
    > > >
    > > > "Dave Peterson" wrote:
    > > >
    > > > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > > > >
    > > > > If you are, make sure you have calculation set to automatic
    > > > > (tools|Options|calculation tab).
    > > > >
    > > > >
    > > > >
    > > > > Rakesh Rampiar wrote:
    > > > > >
    > > > > > Dear Dave
    > > > > >
    > > > > > I managed to run the worksheet macro successfully. When I change the number
    > > > > > on a worksheet with the macro it does automattically change the colour,
    > > > > > however if that same worksheet has a link on from another worksheet in the
    > > > > > same book and when that worksheet has been changed, the worksheet with the
    > > > > > macro does not automatically change colour. I would have to press F2 on that
    > > > > > cell for it to change colour. Is there any way around this.
    > > > > >
    > > > > > Regards
    > > > > >
    > > > > > Rakesh
    > > > > >
    > > > > > "Rakesh Rampiar" wrote:
    > > > > >
    > > > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > > > more?
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson
    > > > >

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  19. #19
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    Hi Dave

    I've got Windows 2000 Professional loaded on my system, I assume I have
    Excel97.

    I changed the range to start from D2 instead of A1. I have 2 work sheets.
    One is where I input the data and the second one is the same as first but is
    used to copy all the inputs made in sheet1, specifically from columns D to H.
    On sheet 2 column G is the average of D to H (as copied from sheet1). (People
    get distracted by seeing the colours change on the actual sheet). I am now
    encountering 2 problems:

    1. How do I set my range more effectively, below is what I have to do in
    order for each of those cells to be activated. I just put a few in this code
    in order to illustrate my point.

    2. It seems that whatever colour is on cell d2, then the rest of the range
    is the same colour, irrespective of what the data in the other cells are.

    Thank you so much for all your help.

    Regards

    Rakesh

    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim myCell As Range
    Dim myColorIndex As Long
    Set myCell = Me.Range
    "$d$2,$d$3,$d$4,$d$5,$e$2,$e$3,$e$4,$e$5,$f$2,$f$3,$f$4,$f$5,$g$2,$g$3,$g$4,$g$5,$h$2,$h$3,$h$4,$h$5")
    If IsNumeric(myCell.Value) Then
    Select Case myCell.Value
    Case Is = 0: myColorIndex = 0 'White
    Case Is <= 1: myColorIndex = 5 'Blue
    Case Is <= 2: myColorIndex = 4 'Green
    Case Is <= 3: myColorIndex = 6 'Yellow
    Case Is <= 4: myColorIndex = 46 'Orange
    Case Is <= 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    Else
    myColorIndex = xlNone
    End If
    myCell.Interior.ColorIndex = myColorIndex
    End Sub

    "Dave Peterson" wrote:

    > What's in A1?
    >
    > What version of excel are you using?
    >
    > Maybe...
    >
    > Option Explicit
    > Private Sub Worksheet_Calculate()
    > Dim myCell As Range
    > Dim myColorIndex As Long
    > Set myCell = Me.Range("$a$1")
    > If IsNumeric(myCell.Value) Then
    > Select Case myCell.Value
    > Case Is = 0: myColorIndex = 0 'White
    > Case Is <= 1: myColorIndex = 5 'Blue
    > Case Is <= 2: myColorIndex = 4 'Green
    > Case Is <= 3: myColorIndex = 6 'Yellow
    > Case Is <= 4: myColorIndex = 46 'Orange
    > Case Is <= 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Else
    > myColorIndex = xlNone
    > End If
    > myCell.Interior.ColorIndex = myColorIndex
    > End Sub
    >
    > This didn't cause any trouble, but...
    >
    > this line:
    > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > is the same as:
    > Case Is <= 2: myColorIndex = 4 'Green
    >
    > I find the second one easier to read.
    >
    > Rakesh Rampiar wrote:
    > >
    > > Hi Dave
    > >
    > > Thanks Dave. Below is how I posted it on excel, however, it now does not
    > > want to run at all. It gives me an error '13' Type Mismatch. Sorry to
    > > bother you.
    > >
    > > Regards
    > >
    > > Rakesh
    > >
    > > Option Explicit
    > >
    > > Private Sub Worksheet_Calculate()
    > >
    > > Dim myCell As Range
    > > Dim myColorIndex As Long
    > >
    > > Set myCell = Me.Range("$a$1")
    > >
    > > Select Case myCell.Value
    > > Case Is = 0: myColorIndex = 2 'White
    > > Case Is = 1, Is < 1: myColorIndex = 5 'Blue
    > > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > Case Is = 4, Is < 4: myColorIndex = 46 'Orange
    > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > myCell.Interior.ColorIndex = myColorIndex
    > >
    > > End Sub
    > >
    > > "Dave Peterson" wrote:
    > >
    > > > You are using the Worksheet_change event. Notice that there is no code in the
    > > > worksheet_calculate procedure.
    > > >
    > > > Option Explicit
    > > > Private Sub Worksheet_Calculate()
    > > > Dim myCell As Range
    > > > Dim myColorIndex As Long
    > > > Set myCell = Me.Range("$a$1")
    > > > Select Case myCell.Value
    > > > Case Is = 0: myColorIndex = 0 'White
    > > > Case Is <= 1: myColorIndex = 22 'Blue
    > > > Case Is <= 2: myColorIndex = 9 'Green
    > > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > > Case Is <= 4: myColorIndex = 12 'Orange
    > > > Case Is <= 5: myColorIndex = 3 'Red
    > > > Case Else
    > > > myColorIndex = xlNone
    > > > End Select
    > > > myCell.Interior.ColorIndex = myColorIndex
    > > > End Sub
    > > >
    > > >
    > > >
    > > > Rakesh Rampiar wrote:
    > > > >
    > > > > Hi Dave
    > > > >
    > > > > Yes (eventually), I am am using the worksheet_calculate event and checked
    > > > > that the calculation tab is on automatic (default), still no joy. I went
    > > > > into that website that McGimpsey suggested but because of my lack knowledge
    > > > > in VBA, could not find what I am looking for.
    > > > >
    > > > > Currently I am using this code: (as suggested by yourself)
    > > > >
    > > > > Private Sub Worksheet_Calculate()
    > > > > End Sub
    > > > >
    > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > Dim myRngToCheck As Range
    > > > > Dim myColorIndex As Long
    > > > > Set myRngToCheck = Me.Range("$a$1")
    > > > > Select Case Target.Value
    > > > > Case Is = 0: myColorIndex = 0 'White
    > > > > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > > > > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > > Case Else
    > > > > myColorIndex = xlNone
    > > > > End Select
    > > > > Target.Interior.ColorIndex = myColorIndex
    > > > >
    > > > > End Sub
    > > > >
    > > > > Now the code works perfect when I type the actual figures on any cell but
    > > > > when there's a formula in a cell the colour of the cell does not change
    > > > > automatically, E.g.
    > > > >
    > > > > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > > > > sum(a1:b1)/2.
    > > > > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > > > > cell C1 only changes if I press F2 on the cell and enter it.
    > > > >
    > > > > Please help.
    > > > >
    > > > > Regards
    > > > >
    > > > > Rakesh
    > > > >
    > > > > "Dave Peterson" wrote:
    > > > >
    > > > > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > > > > >
    > > > > > If you are, make sure you have calculation set to automatic
    > > > > > (tools|Options|calculation tab).
    > > > > >
    > > > > >
    > > > > >
    > > > > > Rakesh Rampiar wrote:
    > > > > > >
    > > > > > > Dear Dave
    > > > > > >
    > > > > > > I managed to run the worksheet macro successfully. When I change the number
    > > > > > > on a worksheet with the macro it does automattically change the colour,
    > > > > > > however if that same worksheet has a link on from another worksheet in the
    > > > > > > same book and when that worksheet has been changed, the worksheet with the
    > > > > > > macro does not automatically change colour. I would have to press F2 on that
    > > > > > > cell for it to change colour. Is there any way around this.
    > > > > > >
    > > > > > > Regards
    > > > > > >
    > > > > > > Rakesh
    > > > > > >
    > > > > > > "Rakesh Rampiar" wrote:
    > > > > > >
    > > > > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > > > > more?
    > > > > >
    > > > > > --
    > > > > >
    > > > > > Dave Peterson
    > > > > >
    > > >
    > > > --
    > > >
    > > > Dave Peterson
    > > >

    >
    > --
    >
    > Dave Peterson
    >


  20. #20
    Dave Peterson
    Guest

    Re: Conditional Formatting

    Maybe something like:

    Option Explicit
    Private Sub Worksheet_Calculate()
    Dim myCell As Range
    Dim myRng As Range
    Dim myColorIndex As Long
    Set myRng = Me.Range("d2:h5")

    For Each myCell In myRng.Cells
    If IsNumeric(myCell.Value) Then
    Select Case myCell.Value
    Case Is = 0: myColorIndex = 0 'White
    Case Is <= 1: myColorIndex = 5 'Blue
    Case Is <= 2: myColorIndex = 4 'Green
    Case Is <= 3: myColorIndex = 6 'Yellow
    Case Is <= 4: myColorIndex = 46 'Orange
    Case Is <= 5: myColorIndex = 3 'Red
    Case Else
    myColorIndex = xlNone
    End Select
    Else
    myColorIndex = xlNone
    End If
    myCell.Interior.ColorIndex = myColorIndex
    Next myCell
    End Sub

    Depending on how your range is configured, you could build a bunch of addresses:

    Set myRng = Me.Range("d2:d5,f3:f88,c239,g2:h45")



    Rakesh Rampiar wrote:
    >
    > Hi Dave
    >
    > I've got Windows 2000 Professional loaded on my system, I assume I have
    > Excel97.
    >
    > I changed the range to start from D2 instead of A1. I have 2 work sheets.
    > One is where I input the data and the second one is the same as first but is
    > used to copy all the inputs made in sheet1, specifically from columns D to H.
    > On sheet 2 column G is the average of D to H (as copied from sheet1). (People
    > get distracted by seeing the colours change on the actual sheet). I am now
    > encountering 2 problems:
    >
    > 1. How do I set my range more effectively, below is what I have to do in
    > order for each of those cells to be activated. I just put a few in this code
    > in order to illustrate my point.
    >
    > 2. It seems that whatever colour is on cell d2, then the rest of the range
    > is the same colour, irrespective of what the data in the other cells are.
    >
    > Thank you so much for all your help.
    >
    > Regards
    >
    > Rakesh
    >
    > Option Explicit
    > Private Sub Worksheet_Calculate()
    > Dim myCell As Range
    > Dim myColorIndex As Long
    > Set myCell = Me.Range
    > "$d$2,$d$3,$d$4,$d$5,$e$2,$e$3,$e$4,$e$5,$f$2,$f$3,$f$4,$f$5,$g$2,$g$3,$g$4,$g$5,$h$2,$h$3,$h$4,$h$5")
    > If IsNumeric(myCell.Value) Then
    > Select Case myCell.Value
    > Case Is = 0: myColorIndex = 0 'White
    > Case Is <= 1: myColorIndex = 5 'Blue
    > Case Is <= 2: myColorIndex = 4 'Green
    > Case Is <= 3: myColorIndex = 6 'Yellow
    > Case Is <= 4: myColorIndex = 46 'Orange
    > Case Is <= 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Else
    > myColorIndex = xlNone
    > End If
    > myCell.Interior.ColorIndex = myColorIndex
    > End Sub
    >
    > "Dave Peterson" wrote:
    >
    > > What's in A1?
    > >
    > > What version of excel are you using?
    > >
    > > Maybe...
    > >
    > > Option Explicit
    > > Private Sub Worksheet_Calculate()
    > > Dim myCell As Range
    > > Dim myColorIndex As Long
    > > Set myCell = Me.Range("$a$1")
    > > If IsNumeric(myCell.Value) Then
    > > Select Case myCell.Value
    > > Case Is = 0: myColorIndex = 0 'White
    > > Case Is <= 1: myColorIndex = 5 'Blue
    > > Case Is <= 2: myColorIndex = 4 'Green
    > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > Case Is <= 4: myColorIndex = 46 'Orange
    > > Case Is <= 5: myColorIndex = 3 'Red
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > Else
    > > myColorIndex = xlNone
    > > End If
    > > myCell.Interior.ColorIndex = myColorIndex
    > > End Sub
    > >
    > > This didn't cause any trouble, but...
    > >
    > > this line:
    > > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > > is the same as:
    > > Case Is <= 2: myColorIndex = 4 'Green
    > >
    > > I find the second one easier to read.
    > >
    > > Rakesh Rampiar wrote:
    > > >
    > > > Hi Dave
    > > >
    > > > Thanks Dave. Below is how I posted it on excel, however, it now does not
    > > > want to run at all. It gives me an error '13' Type Mismatch. Sorry to
    > > > bother you.
    > > >
    > > > Regards
    > > >
    > > > Rakesh
    > > >
    > > > Option Explicit
    > > >
    > > > Private Sub Worksheet_Calculate()
    > > >
    > > > Dim myCell As Range
    > > > Dim myColorIndex As Long
    > > >
    > > > Set myCell = Me.Range("$a$1")
    > > >
    > > > Select Case myCell.Value
    > > > Case Is = 0: myColorIndex = 2 'White
    > > > Case Is = 1, Is < 1: myColorIndex = 5 'Blue
    > > > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > Case Is = 4, Is < 4: myColorIndex = 46 'Orange
    > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > Case Else
    > > > myColorIndex = xlNone
    > > > End Select
    > > > myCell.Interior.ColorIndex = myColorIndex
    > > >
    > > > End Sub
    > > >
    > > > "Dave Peterson" wrote:
    > > >
    > > > > You are using the Worksheet_change event. Notice that there is no code in the
    > > > > worksheet_calculate procedure.
    > > > >
    > > > > Option Explicit
    > > > > Private Sub Worksheet_Calculate()
    > > > > Dim myCell As Range
    > > > > Dim myColorIndex As Long
    > > > > Set myCell = Me.Range("$a$1")
    > > > > Select Case myCell.Value
    > > > > Case Is = 0: myColorIndex = 0 'White
    > > > > Case Is <= 1: myColorIndex = 22 'Blue
    > > > > Case Is <= 2: myColorIndex = 9 'Green
    > > > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > > > Case Is <= 4: myColorIndex = 12 'Orange
    > > > > Case Is <= 5: myColorIndex = 3 'Red
    > > > > Case Else
    > > > > myColorIndex = xlNone
    > > > > End Select
    > > > > myCell.Interior.ColorIndex = myColorIndex
    > > > > End Sub
    > > > >
    > > > >
    > > > >
    > > > > Rakesh Rampiar wrote:
    > > > > >
    > > > > > Hi Dave
    > > > > >
    > > > > > Yes (eventually), I am am using the worksheet_calculate event and checked
    > > > > > that the calculation tab is on automatic (default), still no joy. I went
    > > > > > into that website that McGimpsey suggested but because of my lack knowledge
    > > > > > in VBA, could not find what I am looking for.
    > > > > >
    > > > > > Currently I am using this code: (as suggested by yourself)
    > > > > >
    > > > > > Private Sub Worksheet_Calculate()
    > > > > > End Sub
    > > > > >
    > > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > > Dim myRngToCheck As Range
    > > > > > Dim myColorIndex As Long
    > > > > > Set myRngToCheck = Me.Range("$a$1")
    > > > > > Select Case Target.Value
    > > > > > Case Is = 0: myColorIndex = 0 'White
    > > > > > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > > > > > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > > > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > > > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > > > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > > > Case Else
    > > > > > myColorIndex = xlNone
    > > > > > End Select
    > > > > > Target.Interior.ColorIndex = myColorIndex
    > > > > >
    > > > > > End Sub
    > > > > >
    > > > > > Now the code works perfect when I type the actual figures on any cell but
    > > > > > when there's a formula in a cell the colour of the cell does not change
    > > > > > automatically, E.g.
    > > > > >
    > > > > > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > > > > > sum(a1:b1)/2.
    > > > > > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > > > > > cell C1 only changes if I press F2 on the cell and enter it.
    > > > > >
    > > > > > Please help.
    > > > > >
    > > > > > Regards
    > > > > >
    > > > > > Rakesh
    > > > > >
    > > > > > "Dave Peterson" wrote:
    > > > > >
    > > > > > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > > > > > >
    > > > > > > If you are, make sure you have calculation set to automatic
    > > > > > > (tools|Options|calculation tab).
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > > Rakesh Rampiar wrote:
    > > > > > > >
    > > > > > > > Dear Dave
    > > > > > > >
    > > > > > > > I managed to run the worksheet macro successfully. When I change the number
    > > > > > > > on a worksheet with the macro it does automattically change the colour,
    > > > > > > > however if that same worksheet has a link on from another worksheet in the
    > > > > > > > same book and when that worksheet has been changed, the worksheet with the
    > > > > > > > macro does not automatically change colour. I would have to press F2 on that
    > > > > > > > cell for it to change colour. Is there any way around this.
    > > > > > > >
    > > > > > > > Regards
    > > > > > > >
    > > > > > > > Rakesh
    > > > > > > >
    > > > > > > > "Rakesh Rampiar" wrote:
    > > > > > > >
    > > > > > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > > > > > more?
    > > > > > >
    > > > > > > --
    > > > > > >
    > > > > > > Dave Peterson
    > > > > > >
    > > > >
    > > > > --
    > > > >
    > > > > Dave Peterson
    > > > >

    > >
    > > --
    > >
    > > Dave Peterson
    > >


    --

    Dave Peterson

  21. #21
    Rakesh Rampiar
    Guest

    Re: Conditional Formatting

    Wow! That was perfect.

    "Dave Peterson" wrote:

    > Maybe something like:
    >
    > Option Explicit
    > Private Sub Worksheet_Calculate()
    > Dim myCell As Range
    > Dim myRng As Range
    > Dim myColorIndex As Long
    > Set myRng = Me.Range("d2:h5")
    >
    > For Each myCell In myRng.Cells
    > If IsNumeric(myCell.Value) Then
    > Select Case myCell.Value
    > Case Is = 0: myColorIndex = 0 'White
    > Case Is <= 1: myColorIndex = 5 'Blue
    > Case Is <= 2: myColorIndex = 4 'Green
    > Case Is <= 3: myColorIndex = 6 'Yellow
    > Case Is <= 4: myColorIndex = 46 'Orange
    > Case Is <= 5: myColorIndex = 3 'Red
    > Case Else
    > myColorIndex = xlNone
    > End Select
    > Else
    > myColorIndex = xlNone
    > End If
    > myCell.Interior.ColorIndex = myColorIndex
    > Next myCell
    > End Sub
    >
    > Depending on how your range is configured, you could build a bunch of addresses:
    >
    > Set myRng = Me.Range("d2:d5,f3:f88,c239,g2:h45")
    >
    >
    >
    > Rakesh Rampiar wrote:
    > >
    > > Hi Dave
    > >
    > > I've got Windows 2000 Professional loaded on my system, I assume I have
    > > Excel97.
    > >
    > > I changed the range to start from D2 instead of A1. I have 2 work sheets.
    > > One is where I input the data and the second one is the same as first but is
    > > used to copy all the inputs made in sheet1, specifically from columns D to H.
    > > On sheet 2 column G is the average of D to H (as copied from sheet1). (People
    > > get distracted by seeing the colours change on the actual sheet). I am now
    > > encountering 2 problems:
    > >
    > > 1. How do I set my range more effectively, below is what I have to do in
    > > order for each of those cells to be activated. I just put a few in this code
    > > in order to illustrate my point.
    > >
    > > 2. It seems that whatever colour is on cell d2, then the rest of the range
    > > is the same colour, irrespective of what the data in the other cells are.
    > >
    > > Thank you so much for all your help.
    > >
    > > Regards
    > >
    > > Rakesh
    > >
    > > Option Explicit
    > > Private Sub Worksheet_Calculate()
    > > Dim myCell As Range
    > > Dim myColorIndex As Long
    > > Set myCell = Me.Range
    > > "$d$2,$d$3,$d$4,$d$5,$e$2,$e$3,$e$4,$e$5,$f$2,$f$3,$f$4,$f$5,$g$2,$g$3,$g$4,$g$5,$h$2,$h$3,$h$4,$h$5")
    > > If IsNumeric(myCell.Value) Then
    > > Select Case myCell.Value
    > > Case Is = 0: myColorIndex = 0 'White
    > > Case Is <= 1: myColorIndex = 5 'Blue
    > > Case Is <= 2: myColorIndex = 4 'Green
    > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > Case Is <= 4: myColorIndex = 46 'Orange
    > > Case Is <= 5: myColorIndex = 3 'Red
    > > Case Else
    > > myColorIndex = xlNone
    > > End Select
    > > Else
    > > myColorIndex = xlNone
    > > End If
    > > myCell.Interior.ColorIndex = myColorIndex
    > > End Sub
    > >
    > > "Dave Peterson" wrote:
    > >
    > > > What's in A1?
    > > >
    > > > What version of excel are you using?
    > > >
    > > > Maybe...
    > > >
    > > > Option Explicit
    > > > Private Sub Worksheet_Calculate()
    > > > Dim myCell As Range
    > > > Dim myColorIndex As Long
    > > > Set myCell = Me.Range("$a$1")
    > > > If IsNumeric(myCell.Value) Then
    > > > Select Case myCell.Value
    > > > Case Is = 0: myColorIndex = 0 'White
    > > > Case Is <= 1: myColorIndex = 5 'Blue
    > > > Case Is <= 2: myColorIndex = 4 'Green
    > > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > > Case Is <= 4: myColorIndex = 46 'Orange
    > > > Case Is <= 5: myColorIndex = 3 'Red
    > > > Case Else
    > > > myColorIndex = xlNone
    > > > End Select
    > > > Else
    > > > myColorIndex = xlNone
    > > > End If
    > > > myCell.Interior.ColorIndex = myColorIndex
    > > > End Sub
    > > >
    > > > This didn't cause any trouble, but...
    > > >
    > > > this line:
    > > > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > > > is the same as:
    > > > Case Is <= 2: myColorIndex = 4 'Green
    > > >
    > > > I find the second one easier to read.
    > > >
    > > > Rakesh Rampiar wrote:
    > > > >
    > > > > Hi Dave
    > > > >
    > > > > Thanks Dave. Below is how I posted it on excel, however, it now does not
    > > > > want to run at all. It gives me an error '13' Type Mismatch. Sorry to
    > > > > bother you.
    > > > >
    > > > > Regards
    > > > >
    > > > > Rakesh
    > > > >
    > > > > Option Explicit
    > > > >
    > > > > Private Sub Worksheet_Calculate()
    > > > >
    > > > > Dim myCell As Range
    > > > > Dim myColorIndex As Long
    > > > >
    > > > > Set myCell = Me.Range("$a$1")
    > > > >
    > > > > Select Case myCell.Value
    > > > > Case Is = 0: myColorIndex = 2 'White
    > > > > Case Is = 1, Is < 1: myColorIndex = 5 'Blue
    > > > > Case Is = 2, Is < 2: myColorIndex = 4 'Green
    > > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > > Case Is = 4, Is < 4: myColorIndex = 46 'Orange
    > > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > > Case Else
    > > > > myColorIndex = xlNone
    > > > > End Select
    > > > > myCell.Interior.ColorIndex = myColorIndex
    > > > >
    > > > > End Sub
    > > > >
    > > > > "Dave Peterson" wrote:
    > > > >
    > > > > > You are using the Worksheet_change event. Notice that there is no code in the
    > > > > > worksheet_calculate procedure.
    > > > > >
    > > > > > Option Explicit
    > > > > > Private Sub Worksheet_Calculate()
    > > > > > Dim myCell As Range
    > > > > > Dim myColorIndex As Long
    > > > > > Set myCell = Me.Range("$a$1")
    > > > > > Select Case myCell.Value
    > > > > > Case Is = 0: myColorIndex = 0 'White
    > > > > > Case Is <= 1: myColorIndex = 22 'Blue
    > > > > > Case Is <= 2: myColorIndex = 9 'Green
    > > > > > Case Is <= 3: myColorIndex = 6 'Yellow
    > > > > > Case Is <= 4: myColorIndex = 12 'Orange
    > > > > > Case Is <= 5: myColorIndex = 3 'Red
    > > > > > Case Else
    > > > > > myColorIndex = xlNone
    > > > > > End Select
    > > > > > myCell.Interior.ColorIndex = myColorIndex
    > > > > > End Sub
    > > > > >
    > > > > >
    > > > > >
    > > > > > Rakesh Rampiar wrote:
    > > > > > >
    > > > > > > Hi Dave
    > > > > > >
    > > > > > > Yes (eventually), I am am using the worksheet_calculate event and checked
    > > > > > > that the calculation tab is on automatic (default), still no joy. I went
    > > > > > > into that website that McGimpsey suggested but because of my lack knowledge
    > > > > > > in VBA, could not find what I am looking for.
    > > > > > >
    > > > > > > Currently I am using this code: (as suggested by yourself)
    > > > > > >
    > > > > > > Private Sub Worksheet_Calculate()
    > > > > > > End Sub
    > > > > > >
    > > > > > > Private Sub Worksheet_Change(ByVal Target As Range)
    > > > > > > Dim myRngToCheck As Range
    > > > > > > Dim myColorIndex As Long
    > > > > > > Set myRngToCheck = Me.Range("$a$1")
    > > > > > > Select Case Target.Value
    > > > > > > Case Is = 0: myColorIndex = 0 'White
    > > > > > > Case Is = 1, Is < 1: myColorIndex = 22 'Blue
    > > > > > > Case Is = 2, Is < 2: myColorIndex = 9 'Green
    > > > > > > Case Is = 3, Is < 3: myColorIndex = 6 'Yellow
    > > > > > > Case Is = 4, Is < 4: myColorIndex = 12 'Orange
    > > > > > > Case Is = 5, Is < 5: myColorIndex = 3 'Red
    > > > > > > Case Else
    > > > > > > myColorIndex = xlNone
    > > > > > > End Select
    > > > > > > Target.Interior.ColorIndex = myColorIndex
    > > > > > >
    > > > > > > End Sub
    > > > > > >
    > > > > > > Now the code works perfect when I type the actual figures on any cell but
    > > > > > > when there's a formula in a cell the colour of the cell does not change
    > > > > > > automatically, E.g.
    > > > > > >
    > > > > > > I type in 3 in cell A1 and 4 in cell B1, etc, cell C1 has a formula:
    > > > > > > sum(a1:b1)/2.
    > > > > > > When I typed 3 the cell colour changes and likewise when 4is typed, however
    > > > > > > cell C1 only changes if I press F2 on the cell and enter it.
    > > > > > >
    > > > > > > Please help.
    > > > > > >
    > > > > > > Regards
    > > > > > >
    > > > > > > Rakesh
    > > > > > >
    > > > > > > "Dave Peterson" wrote:
    > > > > > >
    > > > > > > > Are you using the worksheet_calculate event (like J.E. McGimpsey suggested)?
    > > > > > > >
    > > > > > > > If you are, make sure you have calculation set to automatic
    > > > > > > > (tools|Options|calculation tab).
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > > > > Rakesh Rampiar wrote:
    > > > > > > > >
    > > > > > > > > Dear Dave
    > > > > > > > >
    > > > > > > > > I managed to run the worksheet macro successfully. When I change the number
    > > > > > > > > on a worksheet with the macro it does automattically change the colour,
    > > > > > > > > however if that same worksheet has a link on from another worksheet in the
    > > > > > > > > same book and when that worksheet has been changed, the worksheet with the
    > > > > > > > > macro does not automatically change colour. I would have to press F2 on that
    > > > > > > > > cell for it to change colour. Is there any way around this.
    > > > > > > > >
    > > > > > > > > Regards
    > > > > > > > >
    > > > > > > > > Rakesh
    > > > > > > > >
    > > > > > > > > "Rakesh Rampiar" wrote:
    > > > > > > > >
    > > > > > > > > > Currently this fucntion only permits up to a maximum of three conditions. I
    > > > > > > > > > find this a bit limiting. Will Microsoft consider amending this to five or
    > > > > > > > > > more?
    > > > > > > >
    > > > > > > > --
    > > > > > > >
    > > > > > > > Dave Peterson
    > > > > > > >
    > > > > >
    > > > > > --
    > > > > >
    > > > > > Dave Peterson
    > > > > >
    > > >
    > > > --
    > > >
    > > > Dave Peterson
    > > >

    >
    > --
    >
    > Dave Peterson
    >


+ 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