add colours to caracters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to add different colours to different numbers in an excel sheet.

So for example "1234" should be green every time when these determined
caracters (numbers) appears on the sheet.
Can I do it? And if yes, can i match more determined caracters with
different coulours.

Thanks!
 
Hi Sheva,
You can easily accomplish this through CONDITIONAL FORMATTING.
- Highlight the entire sheet (or column that will contain the number that
you are searching for)
- From the menu select FORMAT > Conditional Format
- From the box select CELL VALUE IS > EQUAL TO
- In the box beside that type in the value you are looking to highlight
- Press the FORMAT button and select the color that you wish to apply to
that number

If you want to look for and change the color of other numbers, then click on
ADD and repeat the above steps.

HTH
Tom
 
Option Explicit

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Dim iPos As Long
Const TEST_VALUE_1 As String = "1234"
Const TEST_COLORINDEX_1 As Long = 10
Const TEST_VALUE_2 As String = "789"
Const TEST_COLORINDEX_2 As Long = 5

On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
Select Case True
Case InStr(CStr(.Value), TEST_VALUE_1) > 0:
.Characters(iPos, Len(TEST_VALUE_1)). _
Font.ColorIndex = TEST_COLORINDEX_1
Case InStr(CStr(.Value), TEST_VALUE_2) > 0:
.Characters(iPos, Len(TEST_VALUE_2)). _
Font.ColorIndex = TEST_COLORINDEX_2
'etc.
End Select
End With

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.






--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top