Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Bolding a certain word throughout worksheet?

How do I do it?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Bolding a certain word throughout worksheet?

Suestew,

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


Regards,

Brotha lee

"suestew" wrote:

How do I do it?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Bolding a certain word throughout worksheet?

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" wrote in message
...
How do I do it?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Bolding a certain word throughout worksheet?

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
wrote:

How do I do it?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Bolding a certain word throughout worksheet?

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
...
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" wrote in message
...
How do I do it?








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Bolding a certain word throughout worksheet?

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
wrote:

How do I do it?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Bolding a certain word throughout worksheet?

Thanks

Add this line to top of module.

Option Compare Text


Gord

On Mon, 15 Dec 2008 15:40:09 -0800, JLGWhiz
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
wrote:

How do I do it?




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
Macro for bolding and italicizing word strings suestew Excel Programming 5 December 6th 08 09:31 PM
Bolding Subtotals Orion Cochrane Excel Programming 10 September 2nd 08 05:04 PM
Bolding using VBA Brad Excel Programming 7 March 6th 08 02:33 PM
Bolding Row from VB6 Ian B[_2_] Excel Programming 4 July 9th 05 11:19 PM
Bolding Dale[_12_] Excel Programming 2 September 30th 04 04:21 PM


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

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"