Macro 'Find and Replace' Function

darker008

New Member
Joined
May 19, 2004
Messages
4
Is there a way to create a macro using a
custom user form that will act in the same way as the
'Find and Replace' function. I am asking because I am
looking for a way to limit the amout of changes than can
be done while still giving access.

Thank you for your time!

Mystro...
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Here's a quick example of replacing text using inputboxes & excel's find & replace method. If the sheet is protected you can add some unprotect/protect code before & after the replace code.

If using a custom userform you could assign the values of strMyChar & strMyReplace to two textboxes on the form..

Code:
Sub replace_text()
Dim strMyChar As String
Dim strMyReplace As String
Dim rngMyrange As Range
On Error Resume Next
    Do
        Set rngMyrange = Application.InputBox _
            (prompt:="Select a range of cells to action", Type:=8)
            On Error GoTo 0
'Is a range selected? Exit sub if nowt selected
            If rngMyrange Is Nothing Then
                End
                Else
                Exit Do
            End If
    Loop
strMyChar = Application.InputBox _
            (prompt:="What do you want to replace?", Type:=2)
strMyReplace = Application.InputBox _
            (prompt:="What do you want to replace it with?", Type:=2)
With rngMyrange 'with the range just selected
    .Replace What:=strMyChar, Replacement:=strMyReplace, _
    SearchOrder:=xlByColumns, MatchCase:=True
End With
End Sub

Hope it helps
 
Upvote 0
is there away, (I know there is), to set in the macro what would already be in the input box?
Even if we scrap the first box, which either way dosent
matter if it is there or not
 
Upvote 0
Welcome to the Board!

Just add a bit to Will's code:

<font face=Tahoma>    InputBox _
        Prompt:="What do you want to replace?", _
        Title:="Find & Replace", _
        Default:="Default Text Here"</FONT>

Hope that helps,

Smitty
 
Upvote 0

Forum statistics

Threads
1,215,398
Messages
6,124,693
Members
449,179
Latest member
kfhw720

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