Hello folks, I'm new to VBA and need help making the following code dynamic:
Sub thisnthat()
Dim breakPoint
Dim taxPercent
Dim incomeAmount As Double
Dim taxAmount As Double
Dim rowCount As Integer
Dim lastRow As Long
incomeAmount = Round(Range("d4").Value)
Range("d4").Value = incomeAmount
With Worksheets("Model").Range("d4"<wbr>)
lastRow = Range(.Offset(0, 0), .End(xlDown)).Rows.Count
Do Until .Offset(rowCount, 0).Value = ""
Select Case incomeAmount 'check
Case Is > 75000 'check
taxAmount = incomeAmount * 0.3
Case Is = 75000 'check
taxAmount = incomeAmount * 0.25
Case Is >= 55000 'check
taxAmount = incomeAmount * 0.2
Case Is >= 35000 'check
taxAmount = incomeAmount * 0.15
Case Else
taxAmount = incomeAmount * 0
End Select 'check
Exit Do
rowCount = rowCount + 1
Loop
End With
Range("e4").Value = taxAmount
I've experimented with a few things but don't know enough to get the right syntax.
Below is the screenshot of what my code does (fills in cell E4 correctly- I want it to fill in all the gray squares, including if new income amounts are added to column D)
Sub thisnthat()
Dim breakPoint
Dim taxPercent
Dim incomeAmount As Double
Dim taxAmount As Double
Dim rowCount As Integer
Dim lastRow As Long
incomeAmount = Round(Range("d4").Value)
Range("d4").Value = incomeAmount
With Worksheets("Model").Range("d4"<wbr>)
lastRow = Range(.Offset(0, 0), .End(xlDown)).Rows.Count
Do Until .Offset(rowCount, 0).Value = ""
Select Case incomeAmount 'check
Case Is > 75000 'check
taxAmount = incomeAmount * 0.3
Case Is = 75000 'check
taxAmount = incomeAmount * 0.25
Case Is >= 55000 'check
taxAmount = incomeAmount * 0.2
Case Is >= 35000 'check
taxAmount = incomeAmount * 0.15
Case Else
taxAmount = incomeAmount * 0
End Select 'check
Exit Do
rowCount = rowCount + 1
Loop
End With
Range("e4").Value = taxAmount
I've experimented with a few things but don't know enough to get the right syntax.
Below is the screenshot of what my code does (fills in cell E4 correctly- I want it to fill in all the gray squares, including if new income amounts are added to column D)
Last edited: