View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Fourtrax Fourtrax is offline
external usenet poster
 
Posts: 3
Default How to Evaluate formula results in VBA

Got it! It was the value in the cell itself. I did not have ISERROR in the
function so it was trying to evaluate an error code. Once I fixed the error
code it works. Thanks for your help.

"JLatham" wrote:

Oh, if value of 'i' seems acceptable, go take a look on the worksheet itself
at the cell that is being pointed to and see what is in it. Might be
something special or unexpected.

"Fourtrax" wrote:

I tried what you suggested and I get the following error:
Run time error 13 - type mismatch

It errors on the line:
If Range("AJ" & i) = 0 Then

Any ideas?

"JLatham" wrote:

Why not just simply

If Range("AJ" & i) = 0 then
Range("AJ" & i) = "USED"
End If

I didn't specify .Value because .Value is the default property anyhow. Oh -
and don't forget the Next to close the For loop.

"Fourtrax" wrote:

Hello,

I am trying to add VBA code in Excel to evaluate the results of a Formula in
a specific cell and then to use the result in an If statement.
The macro loops thru each row, and I want to compare the formula result in a
specific cell to see if the result is equal to 0. If the result is equal to 0
then I want to change the value of the cell to a text string.

Here is what I have so far.

Dim intRows As Integer
intRows = Range("C1").CurrentRegion.Rows.Count
'Loop through all rows
For i = 2 To intRows
If Application.Evaluate("AJ & i") = 0 Then
Range("AJ" & i).Value = "USED"
End If

Thanks in advance for your help.

Jeff