If, Then, ElseIf doesn't return the right value

Dustin S

New Member
Joined
Dec 2, 2010
Messages
18
Code:
Sub ActiveMgmtT1()

Dim Multiplier As String
Dim Scenario As Integer
Dim ThisRateR1 As Variant
Dim ThisAmtA1, Initial As Long
Dim NewAmtM1, NewAmt2M1 As Long
Dim NewAmtM2, NewAmt2M2 As Long
Dim NewAmtM3, NewAmt2M3 As Long
Dim NewAmtM4, NewAmt2M4 As Long

Multiplier = Range("AA17").Value
Initial = Range("AB34").Value
Scenario = Range("AA18").Value
ThisAmtA1 = Range("AC34").Value
ThisRateR1 = Range("AD34").Value

NewAmtM1 = Initial - ThisAmtA1
NewAmt2M1 = ThisAmtA1 * ThisRateR1
NewAmtM2 = Initial - (Abs(ThisAmtA1) / ThisRateR1)
NewAmt2M2 = Initial - (Abs(ThisAmtA1) * ThisRateR1)
NewAmtM3 = Abs(Initial) - (ThisAmtA1 / ThisRateR1)
NewAmt2M3 = Initial - Abs(ThisAmtA1)
NewAmtM4 = Abs(Initial) - ThisAmtA1
NewAmt2M4 = Abs(ThisAmtA1) * ThisRateR1

If Multiplier = "M" And Scenario = 1 And ThisAmtA1 > 0 Then
    Range("AB18").Value = NewAmtM1 And Range("AC18").Value = NewAmt2M1
    
ElseIf Multiplier = "M" And Scenario = 2 And ThisAmtA1 > 0 Then
    Range("AB18").Value = NewAmtM2 And Range("AC18").Value = NewAmt2M2
    
ElseIf Multiplier = "M" And Scenario = 3 And ThisAmtA1 > 0 Then
    Range("AB18").Value = NewAmtM3 And Range("AC18").Value = NewAmt2M3
    
ElseIf Multiplier = "M" And Scenario = 4 And ThisAmtA1 > 0 Then
    Range("AB18").Value = NewAmtM4 And Range("AC18").Value = NewAmt2M4

Else
    Range("AB18").Value = 0 And Range("AC18").Value = 0

End If

End Sub

This is probably an easy fix, but every time the macro is run it returns 0, 0 in cells AB18 and AC18.
 
Right now it's at zero, but the values can range from 0.1 to 2000 and be up to four decimal places and will never be negative.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
As long as ThisRateR1 is 0, you will get an error every time you try to divide by it

Code:
NewAmtM2 = Initial - (Abs(ThisAmtA1) / ThisRateR1)

You need to make sure that cell AD34 is never equal to 0.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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