ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Multiple Application.UserNames (https://www.excelbanter.com/excel-discussion-misc-queries/88647-multiple-application-usernames.html)

Bob

Multiple Application.UserNames
 
I am trying to have an if statement with mulitiple user names.
The current code:
If Application.UserName < "User1" Then
executes properly, but it only works for one user

I want to do something like this:
If Application.UserName < ("User1" Or "User2" Or "User3") Then
This of course is incorrect and shows an error

Norman Jones

Multiple Application.UserNames
 
Hi Bob,

One way:

If Application.UserName < "User1" _
And Application.UserName < "User2" _
And Application.UserName < "User3" Then

---
Regards,
Norman


"Bob" wrote in message
...
I am trying to have an if statement with mulitiple user names.
The current code:
If Application.UserName < "User1" Then
executes properly, but it only works for one user

I want to do something like this:
If Application.UserName < ("User1" Or "User2" Or "User3") Then
This of course is incorrect and shows an error




Bob Phillips

Multiple Application.UserNames
 
If Application.UserName < "User1" And _
Application.UserName < "User2" And _
Application.UserName < "User3" Then


--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Bob" wrote in message
...
I am trying to have an if statement with mulitiple user names.
The current code:
If Application.UserName < "User1" Then
executes properly, but it only works for one user

I want to do something like this:
If Application.UserName < ("User1" Or "User2" Or "User3") Then
This of course is incorrect and shows an error




Dave Peterson

Multiple Application.UserNames
 
if application.username = "User1" _
or application.username = "User2" _
or application.username = "User3" then
'it was one of these names
else
'it wasn't one of these names
end if


======
When you get lots of names to check, you may find Select Case easier to read:

Select Case Application.UserName
Case Is = "User1", "User2", "User3"
'do something for these names
Case Is = "User4", "User5", "User6"
'do something for these different names
Case Else
'do something for everyone else
End Select

Bob wrote:

I am trying to have an if statement with mulitiple user names.
The current code:
If Application.UserName < "User1" Then
executes properly, but it only works for one user

I want to do something like this:
If Application.UserName < ("User1" Or "User2" Or "User3") Then
This of course is incorrect and shows an error


--

Dave Peterson

Bob

Multiple Application.UserNames
 
Thank you all. Very helpful.

"Dave Peterson" wrote:

if application.username = "User1" _
or application.username = "User2" _
or application.username = "User3" then
'it was one of these names
else
'it wasn't one of these names
end if


======
When you get lots of names to check, you may find Select Case easier to read:

Select Case Application.UserName
Case Is = "User1", "User2", "User3"
'do something for these names
Case Is = "User4", "User5", "User6"
'do something for these different names
Case Else
'do something for everyone else
End Select

Bob wrote:

I am trying to have an if statement with mulitiple user names.
The current code:
If Application.UserName < "User1" Then
executes properly, but it only works for one user

I want to do something like this:
If Application.UserName < ("User1" Or "User2" Or "User3") Then
This of course is incorrect and shows an error


--

Dave Peterson



All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com