simple but brain dead at the moment

tf37

Board Regular
Joined
Apr 16, 2004
Messages
169
I have a range of cells ("A3:F400") and if they equal "SEE HC" then I wish for that cells color index to be 36.
If range("A3:F400") = "SEE HC" then
cell.select color.index=36
end if
or
Range("A3:F400").Select
If Range = "SEE HC" Then
cell.Select Color.Index = 36
End If
Perhaps I should go back and take a nap for a while...sigh...so simple...
Thanks gang
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try this:

Code:
Dim r as Range
Dim c as Range
Set r = Range("A3:F400")
For Each c in r
    If c.Value = "SEE HC" Then
    c.Interior.ColorIndex = 36
Next c

Then nap... ;)

Note that you *could* accomplish this with conditional formatting also (without VBA)...

Edit:
Right...
Changed c.ColorIndex to c.Interior.ColorIndex as noted by Paul-H

(also, this is XL2003 code. Untested in XL2007/2010)
 
Last edited:
Upvote 0
try one of these
.Interior.ColorIndex = xlNone
.Interior.ColorIndex = 36
.Font.ColorIndex = 1
 
Upvote 0
I think the
Dim r as Range
Dim c as Range
Set r = Range("A3:F400")
For Each c in r
If c.Value = "SEE HC" Then
c.ColorIndex = 36
Next c
will work, but doesn't it require a "end if" ?
Not getting it to function at the moment...using Excel 2000 still :(
And am trying it under a sub routine for the worksheet...of should I just try it in a macro...
The conditional format...looking at that as well...think I'll take that nap :)
 
Upvote 0
Try this:

Code:
Dim r as Range
Dim c as Range
Set r = Range("A3:F400")
For Each c in r
    If c.Value = "SEE HC" Then
    c.Interior.ColorIndex = 36
Next c

Then nap... ;)
Edit:
Right...
Changed c.ColorIndex to c.Interior.ColorIndex as noted by Paul-H

(also, this is XL2003 code. Untested in XL2007/2010)
I don't really like to disturb your well-earned nap xenou, but maybe you really mean
Code:
Dim r As Range
Dim c As Range
Set r = Range("A3:F400")
For Each c In r
    If c.Value = "SEE HC" Then c.Interior.ColorIndex = 36
Next c

or 

Dim r As Range
Dim c As Range
Set r = Range("A3:F400")
For Each c In r
    If c.Value = "SEE HC" Then
        c.Interior.ColorIndex = 36
    End If
Next c
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top