Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-28-2008, 11:01 PM
Ed from AZ
 
Posts: n/a
Use Find/Replace to reformat one word in cells?

I tried to highlight a column and use the Find/Replace to find "FAIL"
in the column and replace with "FAIL" in bold and red. It reformatted
the entire cell contents, rather than just the single word. Is there
a way to restrict the Replace action to just what is in the Find or
Replace box in Excel 2003?

Ed
Reply With Quote
  #2 (permalink)  
Old 04-28-2008, 11:16 PM
Dave Peterson
 
Posts: n/a
Re: Use Find/Replace to reformat one word in cells?

Edit|replace won't work (as you've seen).

You could use a macro, though:

Saved from a previous post:

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", "assemblies", "another", "word", "here")

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(1))

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
With myCell.Characters(Start:=cCtr, _
Length:=Len(myWords(iCtr)))
.Font.ColorIndex = 3
.Font.Bold = True
End With
End If
Next cCtr
Next myCell
End If
Next iCtr
Application.ScreenUpdating = True

End Sub

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

This portion:

With myCell.Characters(Start:=cCtr, _
Length:=Len(myWords(iCtr)))
.Font.ColorIndex = 3
.Font.Bold = True
End With

Changes the color and the boldness.

You may want to save first--so you can close without saving if you don't want to
keep the formatting changes. Remember this kind of formatting only works on
text cells--not formulas--not numbers.

Ed from AZ wrote:
>
> I tried to highlight a column and use the Find/Replace to find "FAIL"
> in the column and replace with "FAIL" in bold and red. It reformatted
> the entire cell contents, rather than just the single word. Is there
> a way to restrict the Replace action to just what is in the Find or
> Replace box in Excel 2003?
>
> Ed


--

Dave Peterson
Reply With Quote
  #3 (permalink)  
Old 04-29-2008, 12:53 AM
Ed from AZ
 
Posts: n/a
Re: Use Find/Replace to reformat one word in cells?

Super, Dave!! Thanks very much!

Ed


On Apr 28, 3:16*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Edit|replace won't work (as you've seen).
>
> You could use a macro, though:
>
> Saved from a previous post:
>
> 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", "assemblies", "another", "word", "here")
>
> * * 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(1))
>
> * * * * * * 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
> * * * * * * * * * * * * With myCell.Characters(Start:=cCtr, _
> * * * * * * * * * * * * * * * * * Length:=Len(myWords(iCtr)))
> * * * * * * * * * * * * * * .Font.ColorIndex = 3
> * * * * * * * * * * * * * * .Font.Bold = True
> * * * * * * * * * * * * End With
> * * * * * * * * * * End If
> * * * * * * * * Next cCtr
> * * * * * * Next myCell
> * * * * End If
> * * Next iCtr
> * * Application.ScreenUpdating = True
>
> End Sub
>
> If you're new to macros, you may want to read David McRitchie's intro at:http://www.mvps.org/dmcritchie/excel/getstarted.htm
>
> This portion:
>
> * * * * * * * * * * * * With myCell.Characters(Start:=cCtr, _
> * * * * * * * * * * * * * * * * * Length:=Len(myWords(iCtr)))
> * * * * * * * * * * * * * * .Font.ColorIndex = 3
> * * * * * * * * * * * * * * .Font.Bold = True
> * * * * * * * * * * * * End With
>
> Changes the color and the boldness.
>
> You may want to save first--so you can close without saving if you don't want to
> keep the formatting changes. *Remember this kind of formatting only works on
> text cells--not formulas--not numbers.
>
> Ed from AZ wrote:
>
> > I tried to highlight a column and use the Find/Replace to find "FAIL"
> > in the column and replace with "FAIL" in bold and red. *It reformatted
> > the entire cell contents, rather than just the single word. *Is there
> > a way to restrict the Replace action to just what is in the Find or
> > Replace box in Excel 2003?

>
> > Ed

>
> --
>
> Dave Peterson


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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



All times are GMT. The time now is 04:25 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
0 Credit Cards | Credit Card | Per Insurance | Cash ISA | MPAA



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114