Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Thu, 4 Sep 2003 10:15:32 -0400, "Bob C" wrote in
microsoft.public.excel.programming: Can someone tell me how I can shorten the below "Or" statement without repeating the entire string? If (frmMaintest.CBox1.Text = "bob") Or (frmMaintest.CBox1.Text = "george") Or (frmMaintest.CBox1.Text = "kevin") Then MsgBox "You must select another name!" Exit Sub ElseIf (frmMaintest.CBox1.Text = "john") Or (frmMaintest.CBox1.Text = "tom") Then MsgBox "This name is acceptable!" End If Maybe I don't quite understand the problem, but to me the two obvious ways of shortening the code (and make it faster, too), seem to be: With frmMaintest.CBox1 If (.Text = "bob") Or (.Text = "george") _ Or (.Text = "kevin") Then MsgBox "You must select another name!" Exit Sub ElseIf (.Text = "john") Or (.Text = "tom") Then MsgBox "This name is acceptable!" End If End With or sTmp=frmMaintest.CBox1.Text If (sTmp = "bob") Or (sTmp = "george") _ Or (sTmp = "kevin") Then MsgBox "You must select another name!" Exit Sub ElseIf (sTmp = "john") Or (sTmp = "tom") Then MsgBox "This name is acceptable!" End If -- Michael Bednarek, IT Manager, TGM Ltd, Brisbane, Australia http://mcmbednarek.tripod.com/ "POST NO BILLS" |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
Can an If statement answer an If statement? | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |