LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Format particular words in a string

On Mar 11, 8:37*am, Glen wrote:
I have been trying this morning to find help topics for this and am
having a bit of trouble getting this to work. *Maybe somebody can
provide me a quick way to do this.

I have cells that I am placing a macro created concatenated string
into. *The string has key words in it that I would like to Bold for
emphasis. *These key words are "Module" and "Lessons". *How do I
search the string and bold those two words throughout the string
without bolding the entire cell?

Thanks,

GTW


I found the following code ina different group from David Peterson. I
changed the keywords and modified the range and it worked
beautifully. Dave Peterson - you rock!

Newsgroups: microsoft.public.excel.misc
From: Dave Peterson
Date: Wed, 10 Sep 2003 16:52:16 -0500
Local: Wed, Sep 10 2003 5:52 pm
Subject: Search and Replace
Reply to author | Forward | Print | Individual message | Show original
| Report this message | Find messages by this author
Not built into excel. You could use a macro, though:

Option Explicit
Sub testme01()


Dim myWords As Variant
Dim myCell As Range
Dim myRng As Range
Dim FirstAddress As String
Dim iCtr As Long
Dim letCtr As Long


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


myWords = Array("test", "bold", "hilight")


If myRng Is Nothing Then
MsgBox "No Text Cells found in Selection"
Exit Sub
End If


For iCtr = LBound(myWords) To UBound(myWords)
With myRng
Set myCell = .Find(What:=myWords(iCtr), After:=.Cells(1),
_
LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)


If Not myCell Is Nothing Then
FirstAddress = myCell.Address
Do
For letCtr = 1 To Len(myCell.Value)
If StrComp(Mid(myCell.Value, letCtr, _
Len(myWords(iCtr))), _
myWords(iCtr), vbTextCompare) = 0
Then
myCell.Characters(Start:=letCtr, _

Length:=Len(myWords(iCtr))) _
.Font.FontStyle =
"Bold"
End If
Next letCtr


Set myCell = .FindNext(myCell)


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


End With
Next iCtr


End Sub


You can just put the words you need to highlight in this line:


myWords = Array("test", "bold", "hilight")


(one word is ok, too.)


If you're new to macros, you may want to read David
 
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
How can I isolate the last two words in a text string? Steve Gibbs Excel Discussion (Misc queries) 7 November 28th 08 11:23 PM
return first TWO or THREE words in string EngelseBoer Excel Discussion (Misc queries) 10 September 7th 08 04:51 PM
split string based on a SET of words [email protected] Excel Discussion (Misc queries) 8 August 3rd 07 03:09 AM
Extracting the last set of words from a text string IPerlovsky Excel Worksheet Functions 14 March 2nd 07 02:47 AM
Break string into words Tommy T Excel Programming 2 January 29th 04 03:48 AM


All times are GMT +1. The time now is 05:22 PM.

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

About Us

"It's about Microsoft Excel"