So close

  • Thread starter Thread starter E2out
  • Start date Start date
E

E2out

Can anyone help me out here? I want to change the font color of a cell
depending on a conditional test (4<cell contents<90)

Here is my code



Sub nums()
Worksheets("sheet1").Activate
Range("b2").Select
Range("b2").Activate
Dim a As Integer
a = Worksheets("sheet1").Range("b2").Value
If (5 < a < 8) Then
Worksheets("sheet1").Range("b2").Font.Color = RGB(255, 0, 0)
Worksheets("sheet1").Range("b2").Font.Color = RGB(0, 0, 255)
End If
End Sub


Thanks!

JP
 
Can anyone help me out here? I want to change the font color of a cell
depending on a conditional test (4<cell contents<90)

Here is my code

Sub nums()
Worksheets("sheet1").Activate
Range("b2").Select
Range("b2").Activate
Dim a As Integer
a = Worksheets("sheet1").Range("b2").Value
If (5 < a < 8) Then
Worksheets("sheet1").Range("b2").Font.Color = RGB(255, 0, 0)
Worksheets("sheet1").Range("b2").Font.Color = RGB(0, 0, 255)
End If
End Sub

Thanks!

JP

Not sure what you want to do here but it looks like you are missing an
"ELSE" between your two sets of the color.
 
I tried it with the "else" and it still didn't work. What I'm trying to do
inside this spreadsheet is to run a macro that will test for a cell value
and if it falls as true inside the (3<cell value<34) then the font will
change to red. I know I'm close to getting it but I've tested it with
different values in "B2" but the font color will not change.
 
Sub nums()
Dim a As Integer
a = Worksheets("sheet1").Range("b2").Value
If 5 < a _
and a < 8 Then
'You're changing B2 twice??????
Worksheets("sheet1").Range("b2").Font.Color = RGB(255, 0, 0)
Worksheets("sheet1").Range("b2").Font.Color = RGB(0, 0, 255)
End If
End Sub
 
So in other words I have to break up the conditional test?

(any number< cell value < bigger number)

I'm not trying to change "B2" twice. What I'm trying to do is change the
font color if the value lies in between the range or change it to the second
color if it doesn't

Again I have to be so close on this one...

Thanks again....

So I have to throw an "Else" in there?
 
How about something like:

Sub nums()
Dim a As Integer
a = Worksheets("sheet1").Range("b2").Value
If 5 < a _
and a < 8 Then
Worksheets("sheet1").Range("b2").Font.Color = RGB(255, 0, 0)
else
Worksheets("sheet1").Range("b2").Font.Color = RGB(0, 0, 255)
End If
End Sub

You may want to look at format|Conditional formatting. You can change the color
of the font based on what the formula evaluates to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top