Results 1 to 19 of 19

Thread: Dynamic tax calculator

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #12
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,709
    Location
    That post was to show you how to look at the logic of your code. That "Subscript Out of Range" error was because you were trying to use the subcript LBound() - 1 There ain't no such animal as a subscript smaller then LBound

    Your code needs to know what sheet the Ranges are on.

    There is no need for an inner loop, the For... Next loop is sufficient.

    This line from your post #5 is just about all you need except when arrBreakPoint(i - 1) causes an error. That happens when i = LBound(arrBreakPoint) or 0
    totalTax = totalTax + (arrBreakPoint(i) - arrBreakPoint(i - 1) * arrTaxPct(i))
    The very first iteration thru the For... next loop needs special handling
    If i = Lbound(array) Then TotalTax = Array1(i) * array2(i)
    Note I didn't use TotalTax = TotalTax + etc? That is because the first time thru, there is no previous TotalTax to add to. We don't want to use any Magic Numbers because your professor will change all the values in the tax table and add a percentage to the bottom income level.

    Now we have
     
    For i = Etc
        If i = Lbound then
            Blah, Blah,
        Else
            Blah, Blah
        End if
    Next i
    I suggest you copy all my posts to Notepad or Word and read them over before you try coding again.

    Since we don't want to charge tax on 15K when the income is only 10K
    TotalTax =  Min(Income, arrBreakPoint(LBound)) * arrTaxPct(LBound))
    I'll let you figure out how to handle (i) <> LBound

    Since we don't want to even enter into any tax calculations unless the Income is above a certain amount
    If Income > breakpoint array(i-1) Then calculate for Arrays(i)
    Last edited by Aussiebear; 04-02-2025 at 05:10 AM.
    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •