I have a UDF that I wrote .... nothing fancy, but I could sure use some help cleaning up. It is very basic and I am not 100% sure where or how I should clean it up so that it is easier on the eyes, easier to follow (doesn't make one cringe just looking at it), better coding etiquette/form/procedure (???), faster, etc.
Any insight anyone can give, would be very helpful, even just pointing me in the right direction.
I am using a lot of IF THEN ELSE statements, 9 of them actually, and I think it is just clunky and bad form ......
What do you think?
TD = 2 digits, ranging from 00 - 99
ST = State abreviation
RefD = Date, ranging from 01/01/2000 - TODAY
FLD = Date, ranging from BLANK - YESTERDAY
RDD = Date, ranging from BLANK - FUTURE DATE
Thanks in advance!
-Spydey
Any insight anyone can give, would be very helpful, even just pointing me in the right direction.
I am using a lot of IF THEN ELSE statements, 9 of them actually, and I think it is just clunky and bad form ......
What do you think?
TD = 2 digits, ranging from 00 - 99
ST = State abreviation
RefD = Date, ranging from 01/01/2000 - TODAY
FLD = Date, ranging from BLANK - YESTERDAY
RDD = Date, ranging from BLANK - FUTURE DATE
Code:
Function Reps(TD, ST, RefD, FLD, RDD)
If Year(RefD) <= 2014 Then
Reps = "TM 0"
Else
If (ST = "CA" Or ST = "MO" Or ST = "NV" Or ST = "MA" Or ST = "AL" Or ST = "AZ" Or ST = "GA" Or ST = "MS" Or ST = "MD" Or ST = "NC" Or ST = "NJ" Or ST = "IL" Or ST = "PA" Or ST = "OR" Or ST = "FL") And FLD <> "" And RDD > Now() Then
Reps = "CTS"
Else
If (TD >= 0 And TD <= 13) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 1"
Else
If (TD >= 14 And TD <= 15) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 2"
Else
If (TD >= 16 And TD <= 31) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 3"
Else
If (TD >= 32 And TD <= 43) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 4"
Else
If (TD >= 44 And TD <= 53) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 5"
Else
If (TD >= 54 And TD <= 67) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 6"
Else
If (TD >= 68 And TD <= 99) And Year(RefD) > 2014 And FLD <> "" And RDD <= Now() Then
Reps = "TM 7"
Else
Reps = "N/A"
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Function
Thanks in advance!
-Spydey