PC Review


Reply
Thread Tools Rate Thread

Bolding a certain word throughout worksheet?

 
 
suestew
Guest
Posts: n/a
 
      15th Dec 2008
How do I do it?


 
Reply With Quote
 
 
 
 
Brotha Lee
Guest
Posts: n/a
 
      15th Dec 2008
Suestew,

Use the conditional formatting which can be found under Format Menu.


Regards,

Brotha lee

"suestew" wrote:

> How do I do it?
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      15th Dec 2008
Sub Test()

BoldWord ActiveSheet, "my-word"

End Sub


Sub BoldWord(ws As Worksheet, sWord As String)
Dim pos As Long
Dim firstAddress As String
Dim vBold
Dim rng As Range
Dim cel As Range

On Error Resume Next
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants, 2)
On Error GoTo 0
If rng Is Nothing Then Exit Sub

With rng

Set cel = .Find(what:=sWord, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not cel Is Nothing Then
firstAddress = cel.Address
Do
pos = InStr(1, cel.Value, sWord)
While pos
vBold = cel.Characters(pos, Len(sWord)).Font.Bold
If vBold = vbNull Then vBold = False
If Not vBold Then
cel.Characters(pos, Len(sWord)).Font.Bold = True
End If

pos = InStr(pos + 1, cel.Value, sWord)
Wend

Set cel = .FindNext(cel)
Loop While Not cel Is Nothing And cel.Address <> firstAddress

End If
End With

End Sub

Regards,
Peter T

"suestew" <(E-Mail Removed)> wrote in message
news:A4F8266D-49D4-401D-9099-(E-Mail Removed)...
> How do I do it?
>
>



 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      15th Dec 2008
Is the word part of a string or by itself?

Do you want to do it Via VBA or just use Conditinal Formatting?

Since you posted in the programming group, here is a macro for VBA method no
matter where the word is located on the sheet.

Sub Bold_Word()
Dim rng As Range
Dim Cell As Range
Dim myword As String
Dim start_str As Integer
Dim Mylen As Integer
Dim N As Single
myword = InputBox("Enter the word ")
If myword = "" Then Exit Sub
Mylen = Len(myword)
Set rng = ActiveSheet.UsedRange
For Each Cell In rng
Cell.Font.Bold = False
start_str = InStr(Cell.Value, myword)
If start_str Then
Cell.Characters(start_str, Mylen).Font.Bold = True
End If
Next Cell
End Sub


Gord Dibben MS Excel MVP

On Mon, 15 Dec 2008 12:11:02 -0800, suestew
<(E-Mail Removed)> wrote:

>How do I do it?
>


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      15th Dec 2008
Probably want case insensitive

Change
> pos = InStr(1, cel.Value, sWord)

to
pos = InStr(1, cel.Value, sWord, vbTextCompare)
and change
> pos = InStr(pos + 1, cel.Value, sWord)

to
pos = InStr(pos + 1, cel.Value, sWord, vbTextCompare)

As written the routine only looks for the word in string constant cells, not
formulas.

Peter T


"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> Sub Test()
>
> BoldWord ActiveSheet, "my-word"
>
> End Sub
>
>
> Sub BoldWord(ws As Worksheet, sWord As String)
> Dim pos As Long
> Dim firstAddress As String
> Dim vBold
> Dim rng As Range
> Dim cel As Range
>
> On Error Resume Next
> Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeConstants, 2)
> On Error GoTo 0
> If rng Is Nothing Then Exit Sub
>
> With rng
>
> Set cel = .Find(what:=sWord, LookIn:=xlValues, _
> LookAt:=xlPart, SearchOrder:=xlByRows, _
> SearchDirection:=xlNext, MatchCase:=False)
> If Not cel Is Nothing Then
> firstAddress = cel.Address
> Do
> pos = InStr(1, cel.Value, sWord)
> While pos
> vBold = cel.Characters(pos, Len(sWord)).Font.Bold
> If vBold = vbNull Then vBold = False
> If Not vBold Then
> cel.Characters(pos, Len(sWord)).Font.Bold = True
> End If
>
> pos = InStr(pos + 1, cel.Value, sWord)
> Wend
>
> Set cel = .FindNext(cel)
> Loop While Not cel Is Nothing And cel.Address <> firstAddress
>
> End If
> End With
>
> End Sub
>
> Regards,
> Peter T
>
> "suestew" <(E-Mail Removed)> wrote in message
> news:A4F8266D-49D4-401D-9099-(E-Mail Removed)...
>> How do I do it?
>>
>>

>
>



 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      15th Dec 2008
Hey Gord, I like that one. Think I'll save it for future use.

"Gord Dibben" wrote:

> Is the word part of a string or by itself?
>
> Do you want to do it Via VBA or just use Conditinal Formatting?
>
> Since you posted in the programming group, here is a macro for VBA method no
> matter where the word is located on the sheet.
>
> Sub Bold_Word()
> Dim rng As Range
> Dim Cell As Range
> Dim myword As String
> Dim start_str As Integer
> Dim Mylen As Integer
> Dim N As Single
> myword = InputBox("Enter the word ")
> If myword = "" Then Exit Sub
> Mylen = Len(myword)
> Set rng = ActiveSheet.UsedRange
> For Each Cell In rng
> Cell.Font.Bold = False
> start_str = InStr(Cell.Value, myword)
> If start_str Then
> Cell.Characters(start_str, Mylen).Font.Bold = True
> End If
> Next Cell
> End Sub
>
>
> Gord Dibben MS Excel MVP
>
> On Mon, 15 Dec 2008 12:11:02 -0800, suestew
> <(E-Mail Removed)> wrote:
>
> >How do I do it?
> >

>
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      16th Dec 2008
Thanks

Add this line to top of module.

Option Compare Text


Gord

On Mon, 15 Dec 2008 15:40:09 -0800, JLGWhiz
<(E-Mail Removed)> wrote:

>Hey Gord, I like that one. Think I'll save it for future use.
>
>"Gord Dibben" wrote:
>
>> Is the word part of a string or by itself?
>>
>> Do you want to do it Via VBA or just use Conditinal Formatting?
>>
>> Since you posted in the programming group, here is a macro for VBA method no
>> matter where the word is located on the sheet.
>>
>> Sub Bold_Word()
>> Dim rng As Range
>> Dim Cell As Range
>> Dim myword As String
>> Dim start_str As Integer
>> Dim Mylen As Integer
>> Dim N As Single
>> myword = InputBox("Enter the word ")
>> If myword = "" Then Exit Sub
>> Mylen = Len(myword)
>> Set rng = ActiveSheet.UsedRange
>> For Each Cell In rng
>> Cell.Font.Bold = False
>> start_str = InStr(Cell.Value, myword)
>> If start_str Then
>> Cell.Characters(start_str, Mylen).Font.Bold = True
>> End If
>> Next Cell
>> End Sub
>>
>>
>> Gord Dibben MS Excel MVP
>>
>> On Mon, 15 Dec 2008 12:11:02 -0800, suestew
>> <(E-Mail Removed)> wrote:
>>
>> >How do I do it?
>> >

>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do I have to select the whole word when bolding? =?Utf-8?B?S2FtcmFu?= Microsoft Word Document Management 1 22nd Aug 2007 09:34 PM
Bolding a word doc from Access blanic via AccessMonster.com Microsoft Access VBA Modules 2 8th Feb 2007 06:00 PM
Word Bolding Problem =?Utf-8?B?Ym94MjAwMw==?= Microsoft Word Document Management 1 16th May 2006 03:51 PM
bolding a word =?Utf-8?B?TWFnZ2ll?= Microsoft Access 4 5th Apr 2006 10:25 PM
MS Word and Bolding John Peterman Microsoft Word Document Management 2 9th Dec 2003 06:42 PM


Features
 

Advertising
 

Newsgroups
 


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