ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select Case question (https://www.excelbanter.com/excel-programming/426256-select-case-question.html)

Brettjg

Select Case question
 
Hi ther, I would like to compress five different Select Case statements into
1 if possible. What I have is:
If lp_cnt = 1 Then
Select Case xxxx
Case m1L
Do some stuff
End Select
End If
If lp_cnt = 2 Then
Select Case xxxx
Case m1L, m2L
Do some stuff
End Select
End If

and so on for 5 tests of lp_cnt.
Can I just set the Case test to "m1L" or "m1L, m2L" depending in the value
of lp_cnt, and therfore have only one Select Case (the "do some stuff" bit is
reasonably long you see)? Regards, Brett

Rick Rothstein

Select Case question
 
The answer could depend on the on tests that you did not show us. can you
copy/paste your entire Select Case block? Also, I'm guessing xxxx is the
name of a variable and it is the same variable in each of your Select Case
statements, right?

--
Rick (MVP - Excel)


"Brettjg" wrote in message
...
Hi ther, I would like to compress five different Select Case statements
into
1 if possible. What I have is:
If lp_cnt = 1 Then
Select Case xxxx
Case m1L
Do some stuff
End Select
End If
If lp_cnt = 2 Then
Select Case xxxx
Case m1L, m2L
Do some stuff
End Select
End If

and so on for 5 tests of lp_cnt.
Can I just set the Case test to "m1L" or "m1L, m2L" depending in the
value
of lp_cnt, and therfore have only one Select Case (the "do some stuff" bit
is
reasonably long you see)? Regards, Brett



Brettjg

Select Case question
 
Apologies Rick, yes xxxx is always the same.

"Rick Rothstein" wrote:

The answer could depend on the on tests that you did not show us. can you
copy/paste your entire Select Case block? Also, I'm guessing xxxx is the
name of a variable and it is the same variable in each of your Select Case
statements, right?

--
Rick (MVP - Excel)


"Brettjg" wrote in message
...
Hi ther, I would like to compress five different Select Case statements
into
1 if possible. What I have is:
If lp_cnt = 1 Then
Select Case xxxx
Case m1L
Do some stuff
End Select
End If
If lp_cnt = 2 Then
Select Case xxxx
Case m1L, m2L
Do some stuff
End Select
End If

and so on for 5 tests of lp_cnt.
Can I just set the Case test to "m1L" or "m1L, m2L" depending in the
value
of lp_cnt, and therfore have only one Select Case (the "do some stuff" bit
is
reasonably long you see)? Regards, Brett





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

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