Thread
:
Color a cell
View Single Post
#
6
Posted to microsoft.public.excel.programming
Don Guillett[_4_]
external usenet poster
Posts: 2,337
Color a cell
A modification of the HELP example for FIND
Sub findandcolorpercentgreen()
With ActiveSheet.UsedRange
Set c = .Find("%", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
'MsgBox c.Address
c.Interior.ColorIndex = 4
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
End Sub
--
Don Guillett
SalesAid Software
"Duncan_J" wrote in message
...
Sorry mine doesn't work... I tried yours and it turns the whole 200
columns
green cause they are formated as percentage.. I'll I need is a find "*%"
and
when found makes the cell green...
Cells.Find(What:="*%", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=
_
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Interior.ColorIndex = 4
Cells.FindNext(After:=ActiveCell).Activate
ActiveCell.Interior.ColorIndex = 4
Cells.FindNext(After:=ActiveCell).Activate
ActiveCell.Interior.ColorIndex = 4
Cells.FindNext(After:=ActiveCell).Activate
ActiveCell.Interior.ColorIndex = 4
This works if I can figure out how to loop it...
Thanks guys,
DJ
"Don Guillett" wrote:
try this
Sub colorpercent()
For Each c In ActiveSheet.UsedRange
If Right(c.NumberFormat, 1) = _
"%" Then c.Interior.ColorIndex = 4
Next
End Sub
--
Don Guillett
SalesAid Software
"Duncan_J" wrote in message
...
I found some code and fiddled with it this works,
Sub ColorCells()
On Error Resume Next
For Each cell In ActiveSheet.Cells.SpecialCells(xlFormulas)
If cell < "%" Then
cell.Interior.ColorIndex = 4
End If
Next
For Each cell In ActiveSheet.Cells.SpecialCells(xlConstants)
If cell < "" Then
cell.Interior.ColorIndex = 4
End If
Next
On Error GoTo 0
End Sub
"Duncan_J" wrote:
Sorry, but that didn't work, Even created a blank sheet and put
"percent" in
a few cells and nothing..
I'm I doing somthing wrong?
DJ
"Don Guillett" wrote:
try this. chg from red (3) to whatever color desired.
Sub Macro2()
For Each c In Selection
If c.Style = "Percent" Then
c.Interior.ColorIndex = 3
End If
Next
End Sub
--
Don Guillett
SalesAid Software
"Duncan_J" wrote in message
...
I'm trying to get a formula in my macro to color every cell with
a %
green.
Any help,
Thanks,
DJ
Reply With Quote
Don Guillett[_4_]
View Public Profile
Find all posts by Don Guillett[_4_]