0

Very new to VBA and so am trying to gain experience by creating a tax calculator macro, but I'm not sure why the values aren't being generated in the right cells or if this is even the best way to go about the tax bracket calculator.

Sub TaxCalculator()
    Dim AGI As Currency
    AGI = Range("AGI").Value
    Select Case AGI
        Case AGI <= Range("'Tax Bracket'!A2").Value
            Range("Net_Income").Value = AGI * (1 - Range("'Tax Bracket'!B2"))
            Range("Monthly_Net_Income").Value = Range("Net_Income") / 12
    End Select
End Sub

A link to the Excel File in Question

Phil Hong
  • 1
  • 1

1 Answers1

4

A Select Case statement can use a less than or equal to (e.g. <=) but not in the way you are trying to implement it.

Sub TaxCalculator()
    Dim AGI As Currency
    AGI = Range("AGI").Value
    Select Case AGI
        Case Is <= Range("'Tax Bracket'!A2").Value
            Range("Net_Income").Value = AGI * (1 - Range("'Tax Bracket'!B2"))
            Range("Monthly_Net_Income").Value = Range("Net_Income") / 12
    End Select
End Sub

Essentially your Case AGI <= Range("'Tax Bracket'!A2").Value was resolving to either True or False as the case may be. Probably unlikely that this was a match for the value in AGI.