VBA Inputbox Find and Replace Help

Jambi46n2

Active Member
Joined
May 24, 2016
Messages
260
Office Version
  1. 365
Platform
  1. Windows
I am trying to conduct an automated Find and Replace with VBA Inputbox to simply replace this:

07 July 2019\SpeeDee Royalty Calculation\07.27\Sales Reports\[07.27.2019 Nexgen SpeeDee Report.xlsx]rptCustomMonthlySalesOverview'!$A$4:$I$102,5,FALSE)

To This:

08 August 2019\SpeeDee Royalty Calculation\08.03\Sales Reports\[08.03.2019 Nexgen SpeeDee Report.xlsx]rptCustomMonthlySalesOverview'!$A$4:$I$102,5,FALSE)

The text in Blue is being replaced correctly, however text in Red is not being replaced.

The code below runs without any errors.

Is there something I'm missing?

Thanks in advance.


Code:
    'Inputbox to Find and Replace
    Dim x As String, y As String, m As String, nm As String
    
        m = VBA.inputbox("Enter Month to Find. Example: 07 July 2019", "Replace What")
        nm = VBA.inputbox("Enter Month to Replace. Example: 08 August 2019 ", "Replace With")
        
        x = VBA.inputbox("Enter Date to Find. Example: 07.27", "Replace What")
        y = VBA.inputbox("Enter Date to Replace. Example: 08.03 ", "Replace With")
        
   On Error Resume Next
                Selection.Replace What:=m, Replacement:=nm
                Selection.Replace What:=x, Replacement:=y
            On Error GoTo 0
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Your code works fine for me.

That is both a relief and concerning at the same time! haha..

Could it be something with my settings? 07.27 does not get replaced with 08.03 when I run it.
 
Upvote 0
That is both a relief and concerning at the same time! haha..

Could it be something with my settings? 07.27 does not get replaced with 08.03 when I run it.
Don't know since I can't reproduce the problem.
Perhaps you are entering the 07.27 with an extra space? Try putting a msgbox after the Inputbox that returns Len(x).
 
Upvote 0
Don't know since I can't reproduce the problem.
Perhaps you are entering the 07.27 with an extra space? Try putting a msgbox after the Inputbox that returns Len(x).

I was able to figure it out.. Since I am doing a find and replace to a formula that references a linked workbook by adding:
Application.Calculation = xlManual
Application.EnableEvents = False
Application.DisplayAlerts = False

Before the find and replace takes place, and returning it to True when finished everything worked properly.

Thanks for letting me know the code was working!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
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