Creating a UDF with the table array inside the code

thecrazyjogger

New Member
Joined
Oct 21, 2014
Messages
6
Hello Forum!

Summary: I want to create a UDF which will give me the result of a cell based on its value but I want the table array to be inside the UDF

Long story: My lookup table array looks like this:

ONETWOTHREE
1001AlphaRegion1
1002BravoRegion1
1003CharlieRegion2
1004DeltaRegion2
1005EchoRegion3
1006FoxtrotRegion1
1007GolfRegion1
1008HotelRegion3

<tbody>
</tbody>
Currently, I have the UDF which VLOOKUPs the required data from the Personal workbook in Excel. What I want is that table range to be inside the UDF itself.
One way I was thinking about doing is below, but considering I have three tables with the smallest table of 30 rows, and the largest table of 210 rows, it will take a good amount of time. Hence I’m asking you guys

Code:
Function WHName(Dude As String)
Application.Volatile
 
COCC = (Dude)
If COCC= "1001" Then
        CCNumber = "Alpha"
ElseIf COCC= "1002" Then
        CCNumber = "Bravo"
ElseIf COCC= "1003" Then
        CCNumber = "Charlie"
ElseIf COCC= "1004" Then
        CCNumber = “Delta”
End If
 
WHName = CCNumber
 
End Function

There has to be a better way. Appreciate all ideas :)
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hardcoding data into the function logic will inevitably lead to this. Unless you are willing to store your array as a resource somewhere, then there is no other way to do it.

One thing you could do is concatenate your data into a long string separated by commas, and then construct your arrays with the Split() function.
 
Upvote 0
Hardcoding data into the function logic will inevitably lead to this. Unless you are willing to store your array as a resource somewhere, then there is no other way to do it.

One thing you could do is concatenate your data into a long string separated by commas, and then construct your arrays with the Split() function.

Hey chrism216, Thank you for replying. Can you tell me how I can store it as a resource somewhere?
 
Upvote 0

Forum statistics

Threads
1,216,732
Messages
6,132,409
Members
449,726
Latest member
Skittlebeanz

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
Back
Top