Re: Easier way to write this
You can use a SELECT CASE statement which will greatly simplify this.
Have a look at my post in the following thread.
http://www.vbforums.com/showthread.php?t=376545
Re: Easier way to write this
But every number gets a different word returned. So how does SELECT CASE simply this??
Re: Easier way to write this
Good point :blush:
What app are you using?
Re: Easier way to write this
Re: Easier way to write this
OK
One way to do this would be to add a worksheet and creat a 2 column list with the codes in column "A" and the descriptions in column "B". You could then use the vlookup function to return the correct description.
(You will need to change the sheet number in the following to reflect the sheet that has your list)
VB Code:
Function Category(Pool)
Category = Application.WorksheetFunction.VLookup(Pool, Worksheets(1).Range("$A:$B"), 2, 0)
End Function
Re: Easier way to write this
Check out this post bye eyeRMonkey. You may be able to adapt this to what you want by creating an enum. looping through it each time, then i = the value you are searching for then just display the name.
Re: Easier way to write this
Actually the Select Case does make it shorter, quicker, and easier to read, eg:
VB Code:
Public Function Category(Pool)
'Custom Function to determine ANG functional categories
Select Case Pool
Case "510": Category = "Suffolk Environmental Payroll"
Case "520": Category = "Suffolk Security Police"
Case "530": Category = "Suffolk Fire Department"
Case "550": Category = "Suffolk State Regulars"
Case "556": Category = "Suffolk Real Property Manager"
Case "555", "556": Category = "Suffolk Hourly/Snow Workers"
Case "512": Category = "Stratton Environmental Payroll"
Case "522": Category = "Stratton Security Police"
....
Case Else: Category = "Undefined"
End Select
End Function
By the way, "556" will never be seen as "Suffolk Hourly/Snow Workers", as "556" is the value for "Suffolk Real Property Manager".
I think the VLookup option would be a good one, but it needs to take these double-values into account too. Would it just mean two lines for "Suffolk Hourly/Snow Workers"?