ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find & Replace in XP (https://www.excelbanter.com/excel-programming/296862-find-replace-xp.html)

Jewel[_2_]

Find & Replace in XP
 
XP now has the ability to do a find & replace based on
formatting, but i ran across an issue. If I type the word
accountant in cell A1 and "accountants are fun" in cell
A2, do a find and replace for the word accountant that
will bold it. In cell a2 it will bold the entire cell
instead of just the word accountant, is there a way around
this if you just want the text and not the entire cell
formatted?

Thanks


Ken Wright

Find & Replace in XP
 
One way though can take a little while if a lot of text:-

Sub ColText()

Dim i As Long
Dim j As Integer
Dim k As Integer
Dim num As Long
Dim ans As String
Dim str As String

ans = InputBox("What string do you want to find")
i = Application.WorksheetFunction.CountIf(ActiveSheet. UsedRange, "*" & ans &
"*")
j = Len(ans)

Cells.Find(what:=ans, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, MatchCase:=False).Activate

For num = 1 To i
k = Application.WorksheetFunction.Find(ans, ActiveCell)
With ActiveCell.Characters(Start:=k, Length:=j).Font
.ColorIndex = 3
.Bold = True
End With
Cells.FindNext(After:=ActiveCell).Activate
Next num

End Sub

If you don't want the colour then comment out the .ColorIndex = 3 line at the
end

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



"Jewel" wrote in message
...
XP now has the ability to do a find & replace based on
formatting, but i ran across an issue. If I type the word
accountant in cell A1 and "accountants are fun" in cell
A2, do a find and replace for the word accountant that
will bold it. In cell a2 it will bold the entire cell
instead of just the word accountant, is there a way around
this if you just want the text and not the entire cell
formatted?

Thanks



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.668 / Virus Database: 430 - Release Date: 24/04/2004



Ken Wright

Find & Replace in XP
 
Note though that this will only do one instance of the data in any one cell.

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



"Ken Wright" wrote in message
...
One way though can take a little while if a lot of text:-

Sub ColText()

Dim i As Long
Dim j As Integer
Dim k As Integer
Dim num As Long
Dim ans As String
Dim str As String

ans = InputBox("What string do you want to find")
i = Application.WorksheetFunction.CountIf(ActiveSheet. UsedRange, "*" & ans &
"*")
j = Len(ans)

Cells.Find(what:=ans, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, MatchCase:=False).Activate

For num = 1 To i
k = Application.WorksheetFunction.Find(ans, ActiveCell)
With ActiveCell.Characters(Start:=k, Length:=j).Font
.ColorIndex = 3
.Bold = True
End With
Cells.FindNext(After:=ActiveCell).Activate
Next num

End Sub

If you don't want the colour then comment out the .ColorIndex = 3 line at the
end

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 97/00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



"Jewel" wrote in message
...
XP now has the ability to do a find & replace based on
formatting, but i ran across an issue. If I type the word
accountant in cell A1 and "accountants are fun" in cell
A2, do a find and replace for the word accountant that
will bold it. In cell a2 it will bold the entire cell
instead of just the word accountant, is there a way around
this if you just want the text and not the entire cell
formatted?

Thanks



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.668 / Virus Database: 430 - Release Date: 24/04/2004




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.668 / Virus Database: 430 - Release Date: 24/04/2004




All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com