if statement with or

T

tinman

Hello,

Could someone help me understand why it doesn't like "If cUser =
"XJOHN" Or "YPAUL" Then" in the macro below? Thanks.

Sub UnprotectAllSheets()
Dim cUser As String
cUser = UCase(Environ("username")) 'change to uppercase because
this seems to be case sensitive.
If cUser = "XJOHN" Or "YPAUL" Then

Dim wSheet As Worksheet
For Each wSheet In ActiveWorkbook.Worksheets
wSheet.Unprotect Password:="opensesame"
Next

Else
UserForm1.Show
End If
End Sub
 
D

Dave Peterson

if cUser = "XJOHN" _
or cUser = "YPAUL" then

or you could use a select case structure:

select case cUser
case is = "XJOHN", "XPAUL"
'DO THE WORK

Sometimes, that "select case" structure is lots easier to modify when you want
to add more options.
 
R

Ryan H

Try this! Hope this helps! If so, let me know, click "YES" below

Sub UnprotectAllSheets()

Dim cUser As String
Dim wSheet As Worksheet

'change to uppercase because this seems to be case sensitive.
cUser = UCase(Environ("username"))
If cUser = "XJOHN" Or cUser = "YPAUL" Then

Dim wSheet As Worksheet
For Each wSheet In ActiveWorkbook.Worksheets
wSheet.Unprotect Password:="opensesame"
Next

Else
UserForm1.Show
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top