LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default optimize If conditional expression?

On 20/01/2010 03:45, Joe User wrote:
"JLGWhiz" wrote:
Well, the options appear to be using If...ElseIf...Else...End If


The "problem" is: it would have to be of the form:

If condition1 Then
Goto doit
Else If condition 2 Then
Goto doit
Else If condition3 Then
doit:
...statements...
End If

Not really a problem. Just undesirable. Also, "...statements..." cannot
be procedurized easily.


How about ...

Function test()
Dim strName As String
strName = "Mr Tibbs"

If CheckGreeting(strName) Then
MsgBox "Hello " & strName
End If

End Function

Function CheckGreeting(strName As String) As Boolean
If Left(strName, 2) = "Mr" Then
CheckGreeting = True
Else If Left(strName, 2) = "Sr" Then
CheckGreeting = True
Else
CheckGreeting = (Left(strName, 2) = "Ms")
End If
End Function


--
Adrian C
 
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
How can I optimize this code? Gustaf Excel Programming 3 January 12th 09 12:43 PM
Conditional Expression in cell TPB Excel Worksheet Functions 3 April 4th 06 08:57 PM
Conditional Expression Question tristatefab Excel Worksheet Functions 4 March 20th 06 08:23 PM
Conditional Formatting OR Expression?? SMac Excel Discussion (Misc queries) 3 May 26th 05 05:10 AM
Optimize SumProduct Christopher Kennedy Excel Discussion (Misc queries) 9 December 10th 04 04:47 PM


All times are GMT +1. The time now is 10:19 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"