Find and Replace showing an error that it used to not have.

hickmanb9

New Member
Joined
Apr 17, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
This macro used to work perfectly fine.

We use it to replace about 1000 different items in a column on an inventory spreadsheet from a supplier.

Unfortunately, it now returns this error message...

We have a separate file that we keep this chart in.

Below is the code we used for it. Can anyone let me know the issue with the code or a better solution?

Sub ReplaceMulValues()
Dim myRange As Range, myList As Range
Set myRange = Application.Selection
Set myRange = Application.InputBox("Select one range to be searched", "Find And Replace Multiple Values", myRange.Address, Type:=8)
Set myList = Application.InputBox("select two column range where find/replace pairs are:", "Find And Replace Multiple Values", Type:=8)
For Each cel In myList.Columns(1).Cells
myRange.Replace what:=cel.Value, replacement:=cel.Offset(0, 1).Value (This is the highlighted line when error comes in. The error states type mismatch error)
Next
End Sub

Typically we copy these to columns into the CSV file as a new sheet. Run the macro. Select column L when prompted and the proceed to select sheet one and then column A & B for the find and replace values.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the Forum!

My guess is that you have an error value, e.g. #N/A, in cel.Offset(0, 1)

When the code breaks:

?cel.Offset(0,1).Address in the immediate window will give you the problem location.
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,800
Members
449,337
Latest member
BBV123

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