Quick Nested If_Else Fix

jmabel01

New Member
Joined
Jan 24, 2011
Messages
10
Public Sub VolumeCalculator()

Dim Height_x As Long
Dim Height_t As Long
Dim Height_m As Long
Dim Height_b As Long
Dim Volume As Long
Dim Radius As Long

Height_x = Range("C4").Value
Height_t = Range("C7").Value
Height_m = Range("C5").Value
Height_b = Range("C8").Value
Volume = 0
Radius = (Range("C6").Value) / 2

If Height_x > Height_t Then
Height_x = Height_x - Height_t
If Height_x > Height_m Then
Height_x = Height_x - Height_m
If Height_x > Height_b Then
Height_x = 0
Else: Height_x = Height_b - Height_x
Volume Fn
Else: Height_x = Height_m - Height_x
Volume Fn
Else: Height_x = Height_t - Height_x
Volume Fn


Range("G9").Value = Volume

End Sub

I get a compile error saying "Else with no If" on the else that I bolded within the quotations.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You are missing several End Ifs. Looks like it should be:

Code:
    If Height_x > Height_t Then
        Height_x = Height_x - Height_t
        If Height_x > Height_m Then
            Height_x = Height_x - Height_m
            If Height_x > Height_b Then
                Height_x = 0
            Else: Height_x = Height_b - Height_x
                Volume Fn
            End If
        Else: Height_x = Height_m - Height_x
            Volume Fn
        End If
    Else: Height_x = Height_t - Height_x
        Volume Fn
    End If
 
Upvote 0
I guess my nested definition is a little off :(

Thanks for the help, I didn't feel too smart after I realized what I was doing wrong...heh
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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
Back
Top