Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
RobDDrums
 
Posts: n/a
Default Conditional Formatting - part of cell only

Is it possible to format a portion of a text string within a cell (as opposed
to the entire cell). For example, I would like to format the word 'gift' in
red font anywhere it a appears in range C2:C417 but only that word, not the
entire cell.
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Conditional Formatting - part of cell only

Not with conditional formatting.

But you could change the actual format for that word (or group of characters)...

Saved from a previous post (or two!):

If you want to change the color of just the characters, you need VBA in all
versions.

You want a macro????

Option Explicit
Option Compare Text
Sub testme()

Application.ScreenUpdating = False

Dim myWords As Variant
Dim myRng As Range
Dim foundCell As Range
Dim iCtr As Long 'word counter
Dim cCtr As Long 'character counter
Dim FirstAddress As String
Dim AllFoundCells As Range
Dim myCell As Range

'add other words here
myWords = Array("widgets")

Set myRng = Selection

On Error Resume Next
Set myRng = Intersect(myRng, _
myRng.Cells.SpecialCells(xlCellTypeConstants, xlTextValues))
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Please choose a range that contains text constants!"
Exit Sub
End If

For iCtr = LBound(myWords) To UBound(myWords)
FirstAddress = ""
Set foundCell = Nothing
With myRng
Set foundCell = .Find(what:=myWords(iCtr), _
LookIn:=xlValues, lookat:=xlPart, _
after:=.Cells(.Cells.Count))

If foundCell Is Nothing Then
MsgBox myWords(iCtr) & " wasn't found!"
Else
Set AllFoundCells = foundCell
FirstAddress = foundCell.Address
Do
If AllFoundCells Is Nothing Then
Set AllFoundCells = foundCell
Else
Set AllFoundCells = Union(foundCell, AllFoundCells)
End If
Set foundCell = .FindNext(foundCell)

Loop While Not foundCell Is Nothing _
And foundCell.Address < FirstAddress
End If

End With

If AllFoundCells Is Nothing Then
'do nothing
Else
For Each myCell In AllFoundCells.Cells
For cCtr = 1 To Len(myCell.Value)
If Mid(myCell.Value, cCtr, Len(myWords(iCtr))) _
= myWords(iCtr) Then
myCell.Characters(Start:=cCtr, _
Length:=Len(myWords(iCtr))) _
.Font.colorindex = 3
End If
Next cCtr
Next myCell
End If
Next iCtr
Application.ScreenUpdating = True

End Sub

This line:
myCell.Characters(Start:=cCtr, _
Length:=Len(myWords(iCtr))) _
.Font.colorindex = 3
changes the color.



If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


RobDDrums wrote:

Is it possible to format a portion of a text string within a cell (as opposed
to the entire cell). For example, I would like to format the word 'gift' in
red font anywhere it a appears in range C2:C417 but only that word, not the
entire cell.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional formatting a full row triggered by a single cell reference... neilcarden Excel Worksheet Functions 1 August 17th 05 02:59 PM
Conditional Formatting Question - Different Cell Colors?? olimits7 Excel Discussion (Misc queries) 2 August 10th 05 04:05 PM
Why won't my conditional formatting display in the cell Cashius War eagle Excel Discussion (Misc queries) 3 February 15th 05 08:38 PM
How to do a conditional formatting based on an adjacent cell Confused Excel Discussion (Misc queries) 2 January 10th 05 09:55 PM
Conditional formatting not available in Excel BAB Excel Discussion (Misc queries) 2 January 1st 05 03:33 PM


All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"