Nested VBA IF statements

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
I cannot get the following nested IF statements to work and get the "Else without If" error for the first Else If statement. I had assumed the first "If" would apply to this

Code:
Private Sub ReconcileNow()

If txtTValue = "" Then
Exit Sub
End If

If C1 = 1 Then
    If Minus = 1 Then
        txtTaC1 = CDbl(txtTpC1) - CDbl(txtTValue)
        txtTaC2 = ""
    Else
    If Minus = 0 Then
        txtTaC1 = CDbl(txtTpC1) + CDbl(txtTValue)
        txtTaC2 = ""
    End If
ElseIf C2 = 1 Then
    If Minus = 1 Then
        txtTaC2 = CDbl(txtTpC2) - CDbl(txtTValue)
        txtTaC1 = ""
    Else
    If Minus = 0 Then
        txtTaC2 = CDbl(txtTpC2) + CDbl(txtTValue)
        txtTaC1 = ""
    End If
Else
If Round = 1 Then
    If Minus = 1 Then
        txtTaR = CDbl(txtTaR) - CDbl(txtTValue)
    Else
    If Minus = 0 Then
        txtTaR = CDbl(txtTaR) + CDbl(txtTValue)
    End If
End If

End Sub

Can anyone spot where I got the code wrong?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I guess this is even simpler though :biggrin:
Code:
multiplier = 1 - 2 * Minus
 
Upvote 0

Forum statistics

Threads
1,217,370
Messages
6,136,156
Members
449,995
Latest member
rport

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