Charles Williams' post provided a good explanation of the differences between the usage of .Value
and .Text
.
In response to the question in your comment, there are many different ways to replace cells. One method would be to use an If...Then
statement, such as:
If Cell().Text = "#N/A" Then
' Your code
End If
You can apply the above for use in a For Each...Next
statement:
Dim Cel as Range
For Each Cel In Worksheets(1).Cells
If Cel.Text = "#N/A" Then
Cel.Value = 0
End If
Next Cel
Also, if you were wanting to look for all errors (such as more than just the #N/A
), you could use IsError()
:
Dim Cel As Range
For Each Cel In Worksheets(1).Cells
If IsError(Cel) Then
Cel.Value = 0
End If
Next Cel
I might add that checking the entire worksheet is time-consuming. It would be wise to add some method of exiting your For statement once you have checked the cells you are needing to, such as utilizing UsedRange
for example.