IIf VBA Problem

P

Pawe³ Zalewski

Hi,

Ok so I know why its allways False :)

but.. still have problem with IIf

i can write
IIf(Replace(Sheet1.Cells(2,5),"X", "B"), "="& FJan, 0)
but than i get an error: Type mismatch.

For VBA: Replace(Sheet1.Cells(2,5),"X", "B") is String value
what schould I do to check i IIF what is under this value and execute this
on sheet2? and get boolean value?
 
R

Ron Rosenfeld

Hi,

Ok so I know why its allways False :)

but.. still have problem with IIf

i can write
IIf(Replace(Sheet1.Cells(2,5),"X", "B"), "="& FJan, 0)
but than i get an error: Type mismatch.

Your syntax seems completely screwed up, and I don't see you doing anything
with the result. Perhaps you are trying to use the syntax for the Excel IF
worksheet function, which is a different function.

Look at HELP and the Example for the IIF function in VBA HELP.

Returns one of two parts, depending on the evaluation of an expression.

Syntax

IIf(expr, truepart, falsepart)

In your statement:

expr = Replace(Sheet1.Cells(2,5),"X", "B")

I don't see how that expr will evaluate to True or False

truepart = "="& FJan

Is FJan defined someplace in your VBA routine? Or are you not using Option
Explicit?

Finally, since the IIF function returns something, you need to store that
return value in something. I don't see that being done.
--ron
 
P

Pawel Zalewski

Under
expr = Replace(Sheet1.Cells(2,5),"X", "B") in the cells i have syntax to
check
fex.B6>B7 or B3+B5>0
value under theb cells are True or False values
 
R

Ron Rosenfeld

Well, what do you get when, in the Immediate Window, when you enter:

?Replace(Sheet1.Cells(2,5),"X", "B")


Also, where are you returning the result of the IIF function???

Look at the Example in HELP!!


Under
expr = Replace(Sheet1.Cells(2,5),"X", "B") in the cells i have syntax to
check
fex.B6>B7 or B3+B5>0
value under theb cells are True or False values

--ron
 
R

Ron Rosenfeld

Even getting a TRUE or a FALSE result here, you still have the other issues I
mentioned.



Under
expr = Replace(Sheet1.Cells(2,5),"X", "B") in the cells i have syntax to
check
fex.B6>B7 or B3+B5>0
value under theb cells are True or False values

--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top