IF - Then statement not meeting criteria

aberenguel

Board Regular
Joined
Aug 10, 2006
Messages
83
Here's my code
Sub balance_transfer()
' balance_transfer Macro
' Written 09/13/2006 by Anthony Berenguel
'

'
Sheets("OUTPUT TRANSFER").Select

If Range("az235").Select = "FALSE" Then
Call rebalance_1
ElseIf Range("AZ235").Select = "FALSE" Then
Call rebalance_2
ElseIf Range("AZ235").Select = "FALSE" Then
Call rebalance_3
End If

End Sub


I have typed FALSE in cell AZ235 of the output transfer sheet. Therefore excel should call the rebalance_1() macro. But it doesn't. When i step through this code it never calls any of the rebalance macros even though AZ235 equals FALSE.

Please help,
Anthony Berenguel
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi Anthony

You are testing the text "FALSE". Maybe AZ235 has the logical value FALSE and not the text "FALSE"?

If AZ235 has the logical value FALSE use

Code:
If Not Range("AZ235").Value Then 
    Call rebalance_1
    Call rebalance_2
    Call rebalance_3
End If
If indeed AZ235 has the text "FALSE", no need for the Select
Code:
If Range("AZ235").Value="FALSE" Then 
    Call rebalance_1
    Call rebalance_2
    Call rebalance_3
End If
Hope this helps
PGC
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
P. S.

Another solution, that will work in both cases, is to use the text property.
Code:
If Range("AZ235").Text="FALSE" Then 
    Call rebalance_1 
    Call rebalance_2 
    Call rebalance_3 
End If
It works fine but is ambiguous, and so not recommended.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

you have "Select" which makes it always TRUE
you see ?
Code:
Sub test()
Range("A1") = True
MsgBox Range("A1").Select
Range("A1") = False
MsgBox Range("A1").Select
End Sub

kind regards,
Erik
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Thank you, Erik, You are right. If the selection is successful it returns True no matter what is the value of the cell. In my case it's clear that the phrase "The mind is quicker than the hand" does not apply.
 

aberenguel

Board Regular
Joined
Aug 10, 2006
Messages
83
thanks everyone!

I have figured it out with all your help. The SELECT part was throwing me off. But thanks again!

Anthony
 

Forum statistics

Threads
1,136,650
Messages
5,676,996
Members
419,667
Latest member
MegEri

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
Top