ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   if statement with or (https://www.excelbanter.com/new-users-excel/255416-if-statement.html)

tinman[_2_]

if statement with or
 
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

Dave Peterson

if statement with or
 
Check your other post.

tinman wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 11:15 PM.

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