ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   More Efficient IF (https://www.excelbanter.com/excel-programming/398307-more-efficient-if.html)

David

More Efficient IF
 
I posted this 2 hrs ago but it seems to have disappeared, apologies if
it reappears and this is a double post!

I have an IF statement thus:

--

IF Variable = 1 or Variable = 2 or Variable = 7 or Variable = 12 then

--

Is there a more efficient way to do this?

In PICK BASIC for example you have the MATCHES function:

--

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

--

Is there anything like that in VBA? Are there any other tips to
improve efficiency/speed in VBA such as putting brackets around
conditionals etc?

Thanks!


Incidental

More Efficient IF
 
Hi David

You could use the select case statement


Select Case variable

Case 1, 2, 7, 12

MsgBox "Variable is either 1,2,7,12"

End Select

hope this helps

S



All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com