vba Find/Replace Problem

hallingh

Well-known Member
Joined
Sep 11, 2010
Messages
769
Hi All. I'm using this code to Find / Replace certain values in a group of cells:

Code:
Range("BG:BR" & LastRow).Select
    Selection.Replace What:="99", Replacement:="0", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False


The code works fine when the value is present, but If I run this and there isn't a 99 in any of the selected cells then it gives me an error saying "Microsoft Excel can not find any data to replace" and telling me to check the search criteria. Obviously the search criteria are fine, I just want it to not show an error message and move on to the next block of code.

Buuuut I'm not sure how to tell it to do this. Any help would be greatly appreciated.

Thanks!

Hank
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I did't get that error with Replace, but there is no need to Select:

Code:
Range("BG:BR" & LastRow).Replace What:="99", Replacement:="0", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 
Upvote 0

Forum statistics

Threads
1,224,395
Messages
6,178,355
Members
452,841
Latest member
GenAkaman

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