View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default More Efficient IF

You can use the worksheet functtion MATCH(). the prblem witth using this
method if the item is not found an error will occur. So you must handle the
errror

Variable = 7
On Error Resume Next
Results = WorksheetFunction.Match(Variable, Array(1, 3, 7, 12), 0)
On Error GoTo 0
If IsEmpty(Results) Then
MsgBox ("Did not find match")
End If

"David" wrote:

Hello

I've got a convaluted IF statement:

--

If Variable = 1 or Variable = 3 or Variable = 7 or Variable = 12 Then

--

Using other languages you could for example do something like this:

--

If Variable MATCHES (1,3,7,12) Then

--

What would be the best way using VBA? Do you increase the efficiency
of the code by adding brackets etc, as in PICK Basic?

Any other general efficiency tips would be appreciated as I've been
asked to update some complex code that was written a long time ago by
one of my ex-colleagues and is deemed inefficient, but I'm not expert
when it comes to VBA, as you probably noticed!

Thanks!