Your AND logic is wrong - both pieces (S > 5000, S < 40000) must be true for the if to be True
Sub drv()
MsgBox test(3000, "Yes")
End Sub
'S = 3000, H = Yes
Function test(S As Double, H As String) As Double
If S > 5000 And S < 40000 Then ' The AND is not true since while 3000 < 40000, 3000 is NOT > 5000
If H = "Yes" Then
test = 0.15
Else
test = 0.25
End If
Else ' so it goes to here
If H = "Yes" Then ' H is YES, so
test = 0 ' the answer is 0
Else
test = 0.01
End If
End If
End Function
If 3000 has different rates, then
Option Explicit
Function getTaxRate(Salary As Double, HasKids As String) As Double
Select Case Salary
Case Is > 90000
getTaxRate = IIf(HasKids = "Yes", 0.42, 0.45)
Case Is >= 40000
getTaxRate = IIf(HasKids = "Yes", 0.28, 0.35)
Case Is >= 5000
getTaxRate = IIf(HasKids = "Yes", 0.15, 0.25)
Case Is >= 3000
getTaxRate = IIf(HasKids = "Yes", 0.09, 0.12)
Case Else
getTaxRate = IIf(HasKids = "Yes", 0#, 0.01)
End Select
End Function