UDF not working as expected

spydey

Active Member
Joined
Sep 19, 2017
Messages
309
Office Version
  1. 2013
Platform
  1. Windows
I have a UDF I based off of a prior I was using.

The prior one works just fine.

But for some reason, this new one just returns a #VALUE error.

I have 3 columns with Headers of:

TD
ST
FLR

In the FLR I input my UDF and it is based off of the TD & ST.

Could someone give it a look over and hopefully point out where I am going wrong for some reason? Please?

Thanks!

Code:
Function FLR(TD, ST)

Dim AryTM1, AryTM2, AryA1, AryR1, AryJ1, AryD1 As Variant


AryTM1 = Array("AR", "CT", "GA", "MD", "NJ", "NY", "OR", "PA", "TN", "WA", "VA")
AryTM2 = Array("AL", "CA", "FL", "IL", "LA", "MA", "MI", "MO", "MS", "NC", "OH", "PR", "TX")
AryA1 = Array("AZ", "CO", "DC", "DE", "IA", "ME", "MN", "NH", "RI", "WV")
AryR1 = Array("IN", "KS", "NE", "NM", "SC", "WI")
AryJ1 = Array("AK", "HI", "ID", "KY", "NV", "ND", "UT")
AryD1 = Array("MT", "OK", "SD", "VT", "WY", "VI")




If UBound(Filter(AryA1, ST, True, vbTextCompare)) >= 0 Then
    Reps = "A1"
    
ElseIf UBound(Filter(AryR1, ST, True, vbTextCompare)) >= 0 Then
    Reps = "R1"
    
ElseIf UBound(Filter(AryJ1, ST, True, vbTextCompare)) >= 0 Then
    Reps = "J1"
    
ElseIf UBound(Filter(AryD1, ST, True, vbTextCompare)) >= 0 Then
    Reps = "D1"
    
ElseIf UBound(Filter(AryTM1, ST, True, vbTextCompare)) >= 0 And TD < 50 Then
    Reps = "A1"
    
ElseIf UBound(Filter(AryTM1, ST, True, vbTextCompare)) >= 0 And TD >= 50 Then
    Reps = "B1"
    
ElseIf UBound(Filter(AryTM2, ST, True, vbTextCompare)) >= 0 And TD < 34 Then
    Reps = "R1"
    
ElseIf UBound(Filter(AryTM2, ST, True, vbTextCompare)) >= 0 And TD >= 34 And TD < 67 Then
    Reps = "J1"
    
ElseIf UBound(Filter(AryTM2, ST, True, vbTextCompare)) >= 0 And TD >= 67 Then
    Reps = "D1"
    
Else
    Reps = "Unkown"
    
End If
End Function

-Spydey
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

spydey

Active Member
Joined
Sep 19, 2017
Messages
309
Office Version
  1. 2013
Platform
  1. Windows
Nevermind, I think I just figured it out.

I forgot to substitute "Reps" from my old code to the new function of FLR.

Something so simple!!! hahahaha lol

-Spydey

P.S. Yup, just tested it and that was the issue. I can't believe I didn't see it before!
 
Last edited:

spydey

Active Member
Joined
Sep 19, 2017
Messages
309
Office Version
  1. 2013
Platform
  1. Windows
Nevermind, I think I just figured it out.

I forgot to substitute "Reps" from my old code to the new function of FLR.

Something so simple!!! hahahaha lol

-Spydey

P.S. Yup, just tested it and that was the issue. I can't believe I didn't see it before!


Correction, not substitute but replace.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,381
Messages
5,601,302
Members
414,440
Latest member
Kim0204

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top