Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Case Selection Example


Hi everyone,

I think that using select case might be my best option fo
accomplishing what I want to but I am really not sure. What I have i
a series of checkboxes on a userform, that a user may select to achiev
a desired result. For example, checkbox1 and checkbox2. A user has
options, he/she may leave both blank, select checkbox1 and leav
checkbox2 blank, select checkbox2 and leave checkbox1 blank, or selec
both checkboxes.

Each of these would result in different code being ran by excel. Ca
anyone give me an example of how I would set this up and use "selec
case" in this instance. Or is there a better way to handle this. (I
my actual program I have six checkboxes)

Once again, thank you in advance for any advice. i
Cheers,
d

--
toocol
-----------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...fo&userid=3160
View this thread: http://www.excelforum.com/showthread.php?threadid=55823

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Case Selection Example

This worked for me (attached to a command button on the userform)

Private Sub CommandButton1_Click()
Dim x As Boolean
Dim y As Boolean

x = Me.CheckBox1.Value
y = Me.CheckBox2.Value

Select Case True
Case x And y
MsgBox "Case 1"
Case x And Not y
MsgBox "Case 2"
Case Not x And y
MsgBox "Case 3"
Case Not x And Not y
MsgBox "Case 4"
End Select

End Sub

"toocold" wrote:


Hi everyone,

I think that using select case might be my best option for
accomplishing what I want to but I am really not sure. What I have is
a series of checkboxes on a userform, that a user may select to achieve
a desired result. For example, checkbox1 and checkbox2. A user has 4
options, he/she may leave both blank, select checkbox1 and leave
checkbox2 blank, select checkbox2 and leave checkbox1 blank, or select
both checkboxes.

Each of these would result in different code being ran by excel. Can
anyone give me an example of how I would set this up and use "select
case" in this instance. Or is there a better way to handle this. (In
my actual program I have six checkboxes)

Once again, thank you in advance for any advice. i
Cheers,
dw


--
toocold
------------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...o&userid=31608
View this thread: http://www.excelforum.com/showthread...hreadid=558230


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Case Selection Example


Hello TooCold,

This macro is for 4 checkboxes. It converts the Checkbox value of True
(Checked) or False (Not checked) to a 1 or 0. Each checkbox value is
then multiplied by a power of 2 to create a bitmapped word of the
checkboxes states. If you want to run code for possible combination of
6 checkboxes you would have 64 Case statements.


Code:
--------------------
Sub SelectExample()

Dim ChkBox1
Dim ChkBox2

With UserForm1
ChkBox1 = Abs(.CheckBox1.Value)
ChkBox2 = Abs(.CheckBox2.Value) * 2
End With

ChkBoxes = ChkBox1 + ChkBox2

Select Case ChkBoxes
Case 0
'Code for 1 and 2 cleared
Case 1
'Code for 1 checked, 2 cleared
Case 2
'Code for 1 cleared, 2 checked
Case 3
'Code for 1 and 2 checked
End Select

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=558230

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Case Selection Example


Thanks guys!

That seems pretty straight forward.

Cheers,
dw


--
toocold
------------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...o&userid=31608
View this thread: http://www.excelforum.com/showthread...hreadid=558230

Reply
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
Case selection in Excel 2003 m2work Excel Worksheet Functions 5 November 1st 08 08:21 PM
change data of entire column from small case to upper case Ann Excel Worksheet Functions 1 August 16th 08 01:06 PM
Changing multiple cell text from lower case to upper case Patti Excel Discussion (Misc queries) 2 January 4th 08 08:35 PM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 09:09 AM
Fix Code: Select Case and "Contains" selection Bettergains Excel Programming 5 April 26th 05 02:22 AM


All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"