Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default multiple conditions for if then else

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default multiple conditions for if then else

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


--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"joemeshuggah" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default multiple conditions for if then else

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

--


Gary

"joemeshuggah" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
count for multiple conditions in multiple columns tturklsu Excel Worksheet Functions 2 July 8th 09 03:42 PM
Setting multiple conditions to return a figure from multiple cells Sapper Excel Discussion (Misc queries) 4 April 26th 09 10:33 PM
SUMPRODUCT or INDEX/MATCH for multiple conditions and multiple rec TravisB Excel Discussion (Misc queries) 21 March 16th 07 09:49 PM
Combining Text from multiple cells under multiple conditions KNS Excel Worksheet Functions 2 June 15th 05 11:00 PM
How to multiple conditions to validate more than 2 conditions to . Bhuvana Govind Excel Worksheet Functions 1 January 28th 05 07:07 PM


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"