View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Kilmer Bob Kilmer is offline
external usenet poster
 
Posts: 280
Default If..Else Statement in Excel

Sheela,
I'll look more closely at your code, but it may not be easy to give the best
advice if the conditions are not clear.

I don't know the limit on nested Ifs, but you can probabaly have more than
you'd care to look at. The following If-ElseIf-Else stetement is valid. I am
not sure how many ElseIfs you can have but I believe the limit is greater
than any legitimate need.

If condition Then
'do something
ElseIf condition Then
'do something
ElseIf condition Then
'do something
ElseIf condition Then
'do something
ElseIf condition Then
'do something
Else 'in any case
'do something
End If

You can combine conditions also
If condition1 And condition2 And condition3 And ... Then
'do something
End If

Sometimes a Select Case is appropriate in place of an If Then Else.

Select Case var
Case is "1"
Case is "a fish"
'etc.
Case Else
End Select

Bob Kilmer

"Sheela" wrote in message
...
What
is max condition can u have in an If...Else Statement. I
have four conditions. How do I apply the if...else
statement on this conditions?

As what I know and have tried, in an if..else statement,
we can only have one "else if" and one "else" within the
structure. I hope I'm not being confusing.

I have include the code:

================================================== ===
If txtDmdPeak.Text <= txtDtotal.Text Then
'Firm - Normal Bill
If Answer = True Then
If txtCalculatedDemand.Text < txtDsbf.Text Then
txtFirmStandbyCharge.Text = (txtDsbf.Value -
txtCalculatedDemand.Value) * txtMaxDmcFirm.Value
If txtFirmStandbyCharge.Value = "" Then
txtFirmStandbyCharge.Value = "0"
Else
txtFirmStandbyCharge.Value = Format
(txtFirmStandbyCharge.Value, "######.##")
End If
End If

If txtDsbf.Text < txtCalculatedDemand.Text Then
If txtCalculatedDemand.Text < txtDtotal.Text
Then
txtFirmStandbyCharge.Text =
(txtDtotal.Value -
txtCalculatedDemand.Value) * txtMaxDmcNonFirm.Value
If txtFirmStandbyCharge.Text = "" Then
txtFirmStandbyCharge.Text = "0"
Else
txtFirmStandbyCharge.Value = Format
(txtFirmStandbyCharge.Value, "######.##")
End If
End If
End If
================================================== ========
I have posted this question earlier but there wasn't any
reply to this. The only advise was replied to me was that
I should replace the inner if to else if. But again, pls
verify the statement that I made in my first & second
paragraph.

Thank you very much in advance for your help.

Sheela