Posted to microsoft.public.excel.programming
|
|
Text color question?
Hi! Dana DeLouis,
I like to try your method but how to set the vba library. Please
guide.
Thanks for the info.
Regards,
Michael.
Dana DeLouis wrote:
*If you would like to try something a little different. If you can
set a vba
library reference to "Regular Expressions 5.5" as listed below, this
should
turn positive numbers to Green, and negative numbers to Red. I have
it set
to work on a "Selection", but you can adjust it easily.
Sub RedGreen()
'// Needs: Microsoft VBScript Regular Expressions 5.5
'// Dana DeLouis
Dim BigRng As Range
Dim cell As Range
Dim Matches
Dim Match
On Error Resume Next
Set BigRng = Selection.SpecialCells(xlConstants, xlTextValues)
If BigRng Is Nothing Then Exit Sub
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "(-*\d+)"
For Each cell In BigRng.Cells
If .Test(cell) Then
Set Matches = .Execute(cell)
For Each Match In Matches
With cell.Characters(Start:=Match.FirstIndex + 1,
Length:=Match.Length).Font
.ColorIndex = IIf(Match.Value = 0, 10, 3)
End With
Next Match
End If
Next cell
End With
Debug.Print
End Sub
HTH
Dana DeLouis
"Michael168 " wrote in
message
...
Hi,VBA pro,
I have a column in a worksheet which hold text string like below;
1,-5,6,-11........
-1,2,-3,............
How can I made the the postive figures in one color and the
negative
figures in another color. I try the macro recorder but it won't
work.
Regards,
Michael.
---
Message posted from http://www.ExcelForum.com/
*
---
Message posted from http://www.ExcelForum.com/
|