PDA

View Full Version : CONDITIONAL FORMATTING CHALLENGE Change numbers to RED



Hotnumbers
12-20-2011, 01:51 PM
CONDITIONAL FORMATTING CHALLENGE
How do I change the Font color on numbers in a cell. Below is an example what a cell may have. Need the numbers to be in red.

ITA 15, NORDC 14, USA 192, CA 1

mikerickson
12-20-2011, 01:58 PM
If that string is the result of a formula, you can't color differnt characters different colors.

Hotnumbers
12-20-2011, 02:02 PM
no formula...

this will be string (text)

Hotnumbers
12-20-2011, 02:28 PM
Have a working code: However, it only works for one cell need it for a range. ANY Ideas?

I need to use this code on specific sheets and on specific columns. for example the range on one sheet would be.

Sheet name October: Range O12:O54, S12:S54: W12:W54. etc... for about 20 columns.
the the same ranges will be used for
Sheet Name November:
Sheet Name December:

Where in the code do i need to make the changes...


WORKING CODE


Sub atest()
Dim i As Long
With Range("A1")
For i = 1 To Len(.Value)
If Asc(Mid(.Value, i, 1)) >= 48 And Asc(Mid(.Value, i, 1)) <= 57 Then
.Characters(i, 1).Font.ColorIndex = 3
End If
Next i
End With
End Sub

mdmackillop
12-20-2011, 02:51 PM
Try this (untested)

Option Explicit

Sub atest()
Dim i As Long
Dim r As Long, c As Long
Dim arr, a
Dim ws As Worksheet

arr = Array("October", "November", "December")
For Each a In arr
Set ws = Sheets(a)
For c = 15 To 95 Step 4 '<== Set nos to suit
For r = 12 To 54
With ws.Cells(r, c)
For i = 1 To Len(.Value)
If Asc(Mid(.Value, i, 1)) >= 48 And Asc(Mid(.Value, i, 1)) <= 57 Then
.Characters(i, 1).Font.ColorIndex = 3
End If
Next i
End With
Next r
Next c
Next
End Sub