View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1367_] Rick Rothstein \(MVP - VB\)[_1367_] is offline
external usenet poster
 
Posts: 1
Default Highlighting part of a cell contents in Excel 2003

Assuming your numbers are always separated by underscore (underline)
characters, I think this macro will do what you want...

Sub ColorCertainNumbers()
Dim X As Long
Dim Start As Long
Dim Cell As Range
Dim Nums() As String
For Each Cell In Range("A1:A10")
Start = 1
Nums = Split(Cell.Value, "_")
For X = 0 To UBound(Nums)
If Not Nums(X) Like "*[!0-9]*" Then
If Nums(X) 32 And Nums(X) < 101 Then
Cell.Characters(Start, Len(Nums(X))).Font.Color = vbRed
End If
End If
Start = Start + Len(Nums(X)) + 1
Next
Next
End Sub

By the way, the code, as written, will handle more than two numbers
(separated by underscores) per cell.

Rick


"Gregg" wrote in message
...
I have values in cells A1:A10 expressed thusly: A1= 23_47
A2=
37_9
etc.. I would like to write code that will highlight individual
numbers in the cells A1:A10 that are greater than 32 and
less than 101. In cell A1 "47" would be highlighted, in cell
A2 "37" would be highlighted. Red can be the highlight color.
Gregg