Advanced find and replace

dunk

New Member
Joined
Feb 19, 2002
Messages
30
Im looking for the VBA code to search a spreadsheet and find a specific word and replace it with another, but the replacement word has to be underlined.
Any help would be greatly appreciated
dunk
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Could give the following a shot:

Sub ReplaceAndUnderline()
Dim rFound As Range
Dim szFirst As String
Dim iCount As Integer
Dim oldval As String
Dim newval As String
oldval = "test"
newval = "testing"
Set rFound = Cells.Find(what:=oldval, lookat:=xlWhole)
iCount = 0
Do While Not rFound Is Nothing
If szFirst = "" Then
szFirst = rFound.Address
ElseIf rFound.Address = szFirst Then
Exit Do
End If
rFound.Value = Application.Substitute(rFound.Value, _
oldval, newval)
rFound.Font.Underline = True
iCount = iCount + 1
Set rFound = Cells.FindNext(rFound)
Loop
End Sub

Just change the oldval and newval strings.


Cheers,

Nate
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,103
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top