String Function

hycho

Registered User.
Local time
Yesterday, 23:23
Joined
Sep 7, 2011
Messages
59
Hi All,

I am trying to write a simple code using a string function, or perhaps using another function I am not aware of.

This is what I want to do, but don't know how to write this code using correct VBA syntax.

Function code (x)
If x equals to one of the values in the following list (1,2,3,4, 5)
then code = "Alpha"
else code = ""
end if
end Function

In the past, I would just write:

x = 1 or x =2 or x =3 or x =4 or x = 5
Then code = "Alpha"

But this writing style can get very time consuming when working with a lot more variables.

Thanks for the help.

- Henry
 
One possibility is the Select Case statement.
Code:
Function code(x) As String
Select Case x
Case 1, 2, 3, 4, 5: code = "Alpha"
Case Else: code = vbNullString
End Select
End Function
 

Users who are viewing this thread

Back
Top Bottom