Yet another VBA issue... Find and Replace

Joined
Nov 19, 2008
Messages
29
Hi Guys,

I am trying to execute a simple find and replace statement...

It needs to loops through all the cells in column H of the sheet called HIST. If it finds the value #N/A then it needs to replace it with the value 0.00

I have tried...

Sub findrep()
Dim target, cell As Range
Dim i, k As String
i = "#N/A"
k = "0.00"
Set target = Sheets("HIST").Range(Range("D1"), Range("D65536").End(xlUp))
For Each cell In target
If cell.Value = i Then cell.Value = k
Next cell
End Sub

But with no success...

Help experts please!!!!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
Sub findrep()
    Sheets("HIST").Columns(4).Replace What:="#N/A", Replacement:="0.00"
End Sub

try it simple way.. The "#N/A" is a result of a formula?
 
Upvote 0
if the #N/A is the result of a formula then it will not replace. If you just don't want the #N/A to display you can do something with the formula

=if(isna(vlookup(a1,table,3,0),0,vlookup(a1,table,3,0))
this is just an example
 
Upvote 0
Thats excellent.

The #N/A was a result of a vLookup not finding a value but i pasted just the value back into the cell.

Sub findrep()
Sheets("HIST").Columns(4).Replace What:="#N/A", Replacement:="0.00"
End Sub

Worked nicely..

Thanks for your help!!
 
Upvote 0
So if you want to copy-paste also (values only) at column 4 (D:D) use this code:
Code:
Sub findrep()
    With Sheets("HIST").Columns(4)
    .Copy
    .PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    .Replace What:="#N/A", Replacement:="0.00"
    End With
End Sub

This code, first copy all column 4 back at it's place as values only, and then replaces.
 
Upvote 0

Forum statistics

Threads
1,215,396
Messages
6,124,685
Members
449,179
Latest member
kfhw720

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