ExcelBanter

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

Gary Keramidas

select case question
 
i have a form with 7 option buttons. i am trying to use select case in the code,
but it never evaluates to true. yet, if i break the code and type
?me.optionbutton1.value in the immediate window, it evaluates to true.

can someone tell me what's wrong?

select case test

Case Me.OptionButton1.Value = True
test = 1
Case Me.OptionButton2.Value = True
test = 2
..
..
..

end select

--


Gary




Randy Harmelink

select case question
 
When you say:

select case test


....you're telling VBA you want to do something based on values of the
variable called "test". Instead, you are giving it conditions.

When you want to specify conditions instead of values for each of the
Cases within the Select Case, your first statement should be:

Select Case TRUE


That tells VBA you are evaluating expressions instead of values for
each Case.


Jay

select case question
 
Does something like this work for you? Not sure, but it seems like there is
something incorrect about your Case statements.

if Me.OptionButton1.Value then Test=1 else Test=2

select case Test

Case 1
VB action statements here.....

Case 2
VB action statements here.....

end select


Good luck,
Jay


"Gary Keramidas" wrote:

i have a form with 7 option buttons. i am trying to use select case in the code,
but it never evaluates to true. yet, if i break the code and type
?me.optionbutton1.value in the immediate window, it evaluates to true.

can someone tell me what's wrong?

select case test

Case Me.OptionButton1.Value = True
test = 1
Case Me.OptionButton2.Value = True
test = 2
..
..
..

end select

--


Gary





Gary Keramidas

select case question
 
thanks randy, figured it was something simple. i knew i could use if statements,
but wanted to use select case.

--


Gary


"Randy Harmelink" wrote in message
oups.com...
When you say:

select case test


...you're telling VBA you want to do something based on values of the
variable called "test". Instead, you are giving it conditions.

When you want to specify conditions instead of values for each of the
Cases within the Select Case, your first statement should be:

Select Case TRUE


That tells VBA you are evaluating expressions instead of values for
each Case.





All times are GMT +1. The time now is 07:21 AM.

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