+ Reply to Thread
Results 1 to 5 of 5

Case Statements and Declarations

Hybrid View

Grilleman Case Statements and... 07-14-2015, 06:48 PM
quekbc Re: Case Statements and... 07-14-2015, 07:54 PM
shg Re: Case Statements and... 07-14-2015, 08:01 PM
quekbc Re: Case Statements and... 07-14-2015, 08:12 PM
mikerickson Re: Case Statements and... 07-14-2015, 08:44 PM
  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Case Statements and Declarations

    I have a User Form with several Multipages. On Multipage 1 the user must select Yes or No from two sets of option buttons and if applicable, check or leave blank two separate checkboxes. How the user fills these fields drives whether or not another set of check boxes resident on a subsequent Multipage (Multipage 5).

    Clicking the “Next” button (Private Sub CommandButton39_Click) at the bottom of Multipage1 is what causes the code to execute. I’m struggling mightily with the case statements and declarations. If anybody can review and comment on the code I have thus far, which now only include three possible scenarios, that would be great.

    Thanks

    Private Sub CommandButton39_Click()
    
    Dim Logistics As Variant
    Dim V As Variant
    Dim x As Variant
    Dim y As Variant
    Dim Z As Variant
    
    V = CheckBox378.Value
    x = OptionButton1.Value
    y = OptionButton2.Value
    Z = CheckBox345.Value
    
    Me.MultiPage1.Value = 11
    
    
    Select Case Logistics
    
    Case Is = y = True And Z = True
    
    Label1582.Visible = True
    Label1583.Visible = True
    CheckBox363.Visible = True
    CheckBox364.Visible = True
    CheckBox365.Visible = True
    CheckBox366.Visible = True
    CheckBox367.Visible = True
    CheckBox368.Visible = True
    CheckBox369.Visible = True
    CheckBox370.Visible = True
    CheckBox371.Visible = True
    CheckBox372.Visible = True
    CheckBox373.Visible = True
    CheckBox374.Visible = True
    
    Case Is = y = True And Z = "" And V = ""
    
    Label1582.Visible = False
    Label1583.Visible = False
    CheckBox363.Visible = False
    CheckBox364.Visible = False
    CheckBox365.Visible = False
    CheckBox366.Visible = False
    CheckBox367.Visible = False
    CheckBox368.Visible = False
    CheckBox369.Visible = False
    CheckBox370.Visible = False
    CheckBox371.Visible = False
    CheckBox372.Visible = False
    CheckBox373.Visible = False
    CheckBox374.Visible = False
    
    Case Is = y = True And Z = False And V = True
    
    Label1582.Visible = False
    Label1583.Visible = False
    CheckBox363.Visible = False
    CheckBox364.Visible = False
    CheckBox365.Visible = False
    CheckBox366.Visible = False
    CheckBox367.Visible = False
    CheckBox368.Visible = False
    CheckBox369.Visible = False
    CheckBox370.Visible = False
    CheckBox371.Visible = False
    CheckBox372.Visible = False
    CheckBox373.Visible = False
    CheckBox374.Visible = False
    
    
    End Select
    
    
    End Sub

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Case Statements and Declarations

    Case Is = y = True And Z = True
    That doesn't look right. Perhaps you meant...
    Case y = True And Z = True

    same goes for

    Case Is = y = True And Z = "" And V = ""
    Case Is = y = True And Z = False And V = True

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Case Statements and Declarations

    Q's suggestion, plus

    Select Case True
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Case Statements and Declarations

    shg's comment got me thinking... what are you trying to do? The Select Case is usually done to test 1 variable across multiple conditions. For example, this code

    If x = 1 Then
        DoPart1
    ElseIf x = 2 Then
        DoPart2
    ElseIf x > 2 Then
        DoPart3
    Else
        DoNegative
    End if
    Is the same as...
    Select Case x
        Case 1
            DoPart1
        Case 2
            DoPart2
        Case Is > 2
            DoPart3
        Case Else
            DoNegative
    End Select
    Perhaps you'll be better off using the If statement

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Case Statements and Declarations

    If you are trying to use Select Case to differentiate between the four possible states of two Option Buttons, you could use something like

    Select Case CStr(OptionButton1.Value) & CStr(OptionButton2.Value)
    
        Case "TrueTrue"
            rem some code
        Case "TrueFalse"
            rem other code
        Case "FalseTrue"
            rem more code
        Case "FalseFalse"
            rem code
    
    End Select
    If not, what is Logistics in the OP code?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multiple IF statements, or a select case?
    By rob2k77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-22-2013, 03:31 PM
  2. [SOLVED] Case Statements and If Statements
    By hawsoon13 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-05-2012, 12:44 PM
  3. problem with syntax on simple Class declarations and Sub declarations
    By ocean_engineer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-28-2011, 03:59 AM
  4. help with if then select case statements
    By timermel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2011, 05:35 PM
  5. Multiple case statements
    By abhijit.pendharkar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2009, 04:12 AM
  6. Case Statements
    By anazarian in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-08-2008, 06:11 AM
  7. Select Case Statements
    By ladeda063610 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2008, 11:25 AM
  8. Declarations Procedure and Duplicate Declarations
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2005, 08:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1