Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environ function with several users

Tags:

excel

vba

Im trying to use the environ function to only allow certain users to use a document

Here is my issue: it works with one username, not with several usernames....

I know nested loops could be a solution here but I think there is probably an easier way. Reference tables also didn’t work successfully

The current code looks like

If ((IDnumber=“12345”) or (IDnumber=“1234”) or IDnumber=“123”))  then 
Msgbox “approved”
Else: msgbox “denied”
like image 234
Excelgoddess Avatar asked Aug 27 '26 08:08

Excelgoddess


1 Answers

Select Case is the appropriate statement to use, here:

Dim strMsg as String
Select Case IDnumber
    Case 12345, 1234, 123
        strMsg = "Approved"
    Case Else
        strMsg = "Denied"
End Select
Msgbox strMsg

If your variable IDnumber is a string (in which case, bad choice of variable name!) then use quotes around each item in the list:

Dim strMsg as String
Select Case IDnumber
    Case "alpha", "bravo", "charlie"
        strMsg = "Approved"
    Case Else
        strMsg = "Denied"
End Select
Msgbox strMsg
like image 109
Olly Avatar answered Aug 29 '26 18:08

Olly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!