Hi there! Apologies in advance for typos and rambling.
So I am currently working on a tax formula as a spare time project. The function takes the year and income figure, and calculates tax based on a few variables.
I have stored these variables in separate worksheets, each named as per what year they pertain to. The idea was that I could pass on the year the user input as the sheet name, and retrieve data from that sheet.
However, I'm having some issues doing that. The debugger stops at the line I have bolded, with no further information as to what error has occurred.
Here's what I have so far (snippet obviously) - I adapted @AlphaFrog's response here as it was a bit cleaner than index match.
Where am I going wrong? I have a feeling it's got something to do with the way I'm referencing the sheets, but not certain.
So I am currently working on a tax formula as a spare time project. The function takes the year and income figure, and calculates tax based on a few variables.
I have stored these variables in separate worksheets, each named as per what year they pertain to. The idea was that I could pass on the year the user input as the sheet name, and retrieve data from that sheet.
However, I'm having some issues doing that. The debugger stops at the line I have bolded, with no further information as to what error has occurred.
Here's what I have so far (snippet obviously) - I adapted @AlphaFrog's response here as it was a bit cleaner than index match.
Code:
'Income taxFunction IncTax(Year, TaxableIncome)
Dim lb As Double 'Lower bracket
Dim ls As Double 'Lump sum
Dim r As Single 'Rate
'Get relevant values from worksheets
With ThisWorkbook.Worksheets(Year)
[B] lb = .Range("A" & Application.Match(TaxableIncome, Range("B:B"), -1))[/B]
End With
With ThisWorkbook.Worksheets(Year)
ls = .Range("C" & Application.Match(TaxableIncome, Range("B:B"), -1))
End With
With ThisWorkbook.Worksheets(Year)
r = .Range("D" & Application.Match(TaxableIncome, Range("B:B"), -1))
End With
'Perform final calculation
IncTax = (ls + ((TaxableIncome - lb) * r))
End Function
Where am I going wrong? I have a feeling it's got something to do with the way I'm referencing the sheets, but not certain.