Recorded vba for "replace text" does not work

123excel

New Member
Joined
Jan 18, 2017
Messages
34
Hi, I have some VBA code that loops through column D and uses the values in range B:X. My problem is that sometimes, the value in some of the cells will have the error #DIVISION/0!. This stops my loop and creates an error. My solution to this was to put the below code before rendering the rest of the VBA code. This replaces #DIVISION/0! with a zero. But the code don't work! It is recorded from when I did it manually and when doing it manually everything works great. But when I run the Macro, the #DIVISION/0! is not replaced.

Anyone have an idea of what to do and why it don't work?

Here is the code I recorded:

Code:
Columns("B:X").Select
    Selection.Replace What:="#DIVISION/0!", Replacement:="0", LookAt:=xlPart _
        , SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
looks fine, did you directly select the errant value and paste directly into the code,. when you step through with f8 can you see your columns are selected first ?
 
Upvote 0
I am intrigued, and this may be totally irrelevant ...
Excel returns #DIV/0! when dividing by zero, so why #DIVISION/0! ?
 
Last edited:
Upvote 0
This is so weird.

For me, Excel is showing #Division/0! and when using this manually it works great. However, after your comment Yongle I changed it to #div/0! In the vba and now it works!

I dont know why this is but this was the solution.

So thanks for your help!

Hopefully this can save the headache for some other people to.
 
Upvote 0
what language is in installed in ?
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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