View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gregg Gregg is offline
external usenet poster
 
Posts: 12
Default Highlighting part of a cell contents in Excel 2003

First, thanks for your time Rick. I ran the macro on a sample column of
cells into which I had entered numbers which were separated by _
(underscore). The correct numbers' fonts were changed from black to red.
Can the background of the space the numbers occupy be red and the numbers
stay black?
A second problem is that though the macro worked right on the sample column
of cells with values only(numbers separated by underscores), when I ran the
macro on a column of numbers separated by underscores which had been
generated by a concatenation of values from two other columns the font color
of all the numbers in the cell were red if the first number in the cell was
32 and <101, but if the first number in the cell was outside these

parameters all the numbers in the cell stayed black even if there were
subsequent numbers in the cell which were 32 and 101. Sorry to be so long
in getting back to you. I'm in Vancouver, Canada.
--
Gregg


"Rick Rothstein (MVP - VB)" wrote:

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