If logical statement and a function

S

smandula

Function as follows:

Function ReverseText(myText)
ReverseText = StrReverse(myText)
End Function

Purpose:
to change cell value 35 into cell value 53
this is not a problem.

However, I do not want to exceed 70 in this mirror image.
i.e. 19 becomes 91 which higher than 70 in cell C2

Using:
=If (C2>70,," ") doesn't work for me, it is not text but a value,
if I add =C2+1 which is 91 + 1 it equals 92
What am I missing?
Which Thanks
 
S

smandula

Solution, as I pushed the enter button,

=IF(C2>70,C2,1)

With Thanks

It still doesn't work! I need C2 to register as a value.
If C2 is greater than 70 to register as a blank

=IF(C2<70,C2," "
Cell A1 has the variable ie 35
Cell C2has a formula =ReverseText(A1)
Cell D3 has the above formula =IF(C2<70,C2," ")
Any opinions,
 
J

JoeU2004

smandula said:
Cell A1 has the variable ie 35
Cell C2has a formula =ReverseText(A1)
Cell D3 has the above formula =IF(C2<70,C2," ")

At a minimum, try:

=if(--C2<70, C2, "")

Note: I use "", not " ". The latter will cause huge problems for you
later.

The problem you are having is: your ReverseText returns text, not a number.
In a comparison, text is always considered greater than any number. The
form --C2 ensures that the text (presumed to be numeric string) is converted
to a number for the comparison.

Any opinions

Many.

First, why not have this handled in the UDF?

Second, do you really what the UDF to return a number (as long as it meets
the criteria), not text?

Third, why use a UDF in the first place?

If you want to handle this in the UDF, you would write:

Function rt(txt)
x = StrReverse(txt)
If IsNumeric(x) And x < 70 Then rt = x Else rt = ""
End Function

If you want the UDF to return a number instead of text, then write:

Function rt(txt)
x = StrReverse(txt)
If IsNumeric(x) And x < 70 Then rt = --x Else rt = ""
End Function


----- original message -----

Solution, as I pushed the enter button,

=IF(C2>70,C2,1)

With Thanks

It still doesn't work! I need C2 to register as a value.
If C2 is greater than 70 to register as a blank

=IF(C2<70,C2," "
Cell A1 has the variable ie 35
Cell C2has a formula =ReverseText(A1)
Cell D3 has the above formula =IF(C2<70,C2," ")
Any opinions,
 

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