Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Change the font colour (97/2000)

    I am creating an Excel form that users are required to select a number of drop downs for an answer to a survey inspection. Depending on what is selected it provides a predefined weighting to a score. These scores are added up and depending on the score txtWarn updates with Low, Medium or High.

    What I would like to do is if it is Low then the text is green, if medium-amber and if High Red.

    Here is a snippet of the code, but I cannot seem to work out the color change aspect:
    ..............................................
    If txtRisk > 18 Then
    txtWarn = "High"

    ElseIf txtRisk >= 13 And txtRisk < 18 Then
    txtWarn = "Medium"

    Else

    txtWarn = "Low"

    End If
    ...........................................


    Can you help?
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the font colour (97/2000)

    Assuming this is a UserForm:

    Select Case txtRisk
    Case Is < 13
    txtWarn = "Low"
    txtWarn.ForeColor = vbGreen
    Case Is >= 18
    txtWarn = "High"
    txtWarn.ForeColor = vbRed
    Case Else
    txtWarn = "Medium"
    txtWarn.ForeColor = RGB(255, 128, 0)
    End Select

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the font colour (97/2000)

    Hi Hans

    That's the cookie. I forgot how vivid vbGreen is, I am off to the optician now, suffering from retinal burnt out!!!

    Jerry
    Jerry

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the font colour (97/2000)

    Are you sure that's not from looking at the Venus transit directly? <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    You can specify your own RGB colors, e.g. RGB(0,128,0) is dark green.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the font colour (97/2000)

    Thanks Hans

    No the original was great.

    Jerry
    Jerry

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change the font colour (97/2000)

    Is txtRisk a number or is it text? If it is a number, then it is extremely poorly named. If it is text, then using it in a numeric comparison could cause problems.
    Legare Coleman

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the font colour (97/2000)

    Legare, in this case, txtRisk is not a VBA variable, but a text box on a UserForm. It is a widely used convention to give text boxes names with prefix txt, whatever their contents.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the font colour (97/2000)

    Hi Legare

    Thanks for your concern.

    Just to clarify. txtRisk is a text box on a form that is storing a numeric value which is the sum of values taken from hidden text boxes.

    txtWarn, another text box, is 'looking' at the value txtRisk and then changing its content depending on the result.

    Further to Hans, txt is a standard prefix for text boxes on a form. Thanks for having a look though <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Jerry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •