multiple If conditions

anziga

Board Regular
Joined
Feb 4, 2011
Messages
55
If I check system logon/username and do something like:
Code:
If UserName <> "johndoe" Then ActiveWorkbook.Close True
this works, but if I want to set more possible users, like:
Code:
If UserName <> "johndoe" Or If UserName <> "janedoe" Then ActiveWorkbook.Close
this doesn't work. Any idea what is the correct way to do this? Or is there any other way to set authorized users for the workbook, without user's input?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
if its not johndoe OR not Janedoe would the result not always be true?

I think you might want an AND


I might be confusing myself here ?!?
 
Upvote 0
Only johndoe or janedoe should be able to open/use the workbook, that is, if either one is the current system user.
 
Upvote 0
Try
Code:
If UserName <> "johndoe" Or UserName <> "janedoe" Then ActiveWorkbook.Close
 
Upvote 0
Have you checked the syntax of "johndoe" and "janedoe" against what is entered in the system
Make sure there isn't a leading space or seperator.....or capitalisation in the names.
 
Upvote 0
I double checked, but for some reason it just doesn't work. I did a test:
Code:
If UserName <> "johndoe" Then
If UserName <> "janedoe" Then ActiveWorkbook.Close True
End If
this works, if either one is logged in, document opens OK, but if the user is not either one, document will closes as it should do. But not sure how it works, if there are more authorized users, but in my case I only need two, so it's OK for now.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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