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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 04:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com