View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Multiple Formats per Cell

Timo

Sub color_words()
Dim Cell As Range, tempR As Range, mystring As String, _
myword As String, rng As Range
mystring = InputBox("Enter the search string")
If mystring = "" Then Exit Sub
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = UCase(mystring) Then
If tempR Is Nothing Then
Set tempR = Cell
Else
Set tempR = Union(tempR, Cell)
End If
End If
Next Cell
If tempR Is Nothing Then
End
End If
tempR.Select
myword = InputBox("Enter the word to format ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = Selection
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, UCase(myword))
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Wed, 26 Nov 2008 12:06:01 -0800, Timo
wrote:

I'm trying to search for specific words in a MsExcel spreadsheet and format
them (using either a macro or formula) with multiple font colors

(e.g. search for "MY NAME IS TIM", and format it so the word "NAME" would be
BOLD RED, and all the other text would be black.

I'm basically trying to highlight individual words only, but not the entire
text string or the entire cell.

Is there a way to do this with either a formula or macro?