Find and Replace using Macros

MBAhelp

New Member
Joined
Nov 2, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi! I'm trying to do this in Excel using Macros. I can't find any code to do this:
  • The user should be able to push a button on the Large Dataset tab that brings up a user input box. (Hint: Learn how to do this by watching the tutorial video on creating a button)
  • The macro should prompt the user to update a field (any field), based on the user’s input on the following items:
  • The old text that you would like to change (using an InputBox) (Hint: Learn how to do this by watching the tutorial video on InputBox)
  • The new text that you would like to have instead (using another InputBox)
  • The macro should then search for the old text, and replace it with the new text (Hint: Record this macro step)
  • When the macro finishes running, please pop a message box telling the user that the job is done (using a MsgBox) (Hint: Learn how to do this by watching the tutorial video on MsgBox)
  • Associate the macro to a button, so the user can run the macro with the click of a button.
I should be able to do this using the button:
  • Johnny Robertson’s new last Name: Robertson‐Casey
  • Emilio quit his job and now Allison has to take over his clients.
  • All Chevy trucks are now replaced by Chrysler vans

Thank you!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
That did work!

Any idea how I can make make a push button that will bring up the input box?
 
Upvote 0
Thank you!
I also need a message box to come up after to display a "the job is done" message
 
Upvote 0
I figured it all out!

In case anyone else needs it
Sub Find_and_Replace()


Dim Title As Variant
Dim sInput(2) As Variant
Dim i As Integer


Title = Array("is the old text you'd like to change?", "would you like to replace it with?")
i = 0
Do
sInput(i) = InputBox("What " & Title(i))
If StrPtr(sInput(i)) = 0 Then Exit Sub
If Len(sInput(i)) = 0 Then
MsgBox "You must enter a value.", 48, "Entry Required"


Else
i = i + 1
End If
Loop Until i > 1

MsgBox "The job is done!"


Sheets("Large Dataset").Range("A1:S450").Replace What:=sInput(0), _
Replacement:=sInput(1), _
LookAt:=xlPart, _
MatchCase:=False
End Sub

Then add the button:
 
Upvote 0

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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