![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
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 |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 30
|
This works great, thank you very much.
|
|
|
|
|
|
#4 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
Glad to hear it. Good hunting.
Cheers, Nate |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|