multiple conditions for if then else

J

joemeshuggah

using the following code to avoid printing restrictions on a specific set of
user ids...what is the correct way to add additional user ids (e.g. User2,
User3, etc) to the if statement?

Private Sub Workbook_BeforePrint(Cancel As Boolean)


If Application.UserName <> "User1" Then

Dim ws As Worksheet
Cancel = True
Application.EnableEvents = False
For Each ws In ActiveWindow.SelectedSheets
Select Case ws.Name
Case "Daily", "Team", "Individual": ws.PrintOut
End Select
Next ws
Application.EnableEvents = True

Else

End If

End Sub
 
G

Gary Keramidas

see if something like this would work:

Sub test()
Dim ws As Worksheet
Select Case UCase(Application.UserName)
Case "USER1", "USER2"
Application.EnableEvents = False
For Each ws In Worksheets(Array("Daily", "Team", "Individual"))
ws.PrintPreview
Next ws
Application.EnableEvents = True
Case Else
End Select
End Sub
 
M

Michael

Use the Select Case statement as an alternative to using ElseIf in
If...Then...Else statements when comparing one expression to several
different values. While If...Then...Else statements can evaluate a different
expression for each ElseIf statement, the Select Case statement evaluates an
expression only once, at the top of the control structure.

Example1:
If Application.UserName = "User1" Then
your code
Else if
Application.UserName = "User2" then

End if

Example2:
Select Case UserID
Case User1
Your code
Case User2,User3
Your code
Case User4
Your code
Case Else
Your Code
End Select
 

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