Select Case Problem

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please consider this userform initialization code.

Rich (BB code):
Private Sub UserForm_Initialize()

    'Hide frames
    F1_WCF.Visible = False
    F2_WCA.Visible = False
    F3_WCO.Visible = False
    F4_CCF.Visible = False
    F5_CCA.Visible = False
    F6_CCO.Visible = False
    F7_PTD.Visible = False
    F8_PAD.Visible = False
    F9_CNS.Visible = False
    F10_CNR.Visible = False
    F11_DEL.Visible = False
    F12_CRQ.Visible = False
    F13_WCT.Visible = False
    F14_CCT.Visible = False

    Select Case uf8_post.uf8_cstat.Value
        Case "WCF"  '1
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            Me.F1_WCF.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8a_wc_staff1.List() = ws_lists.Range("U17:U24").Value
            Me.uf8a_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8a_commby.List() = ws_lists.Range("U17:U29").Value
            Me.cb_acm_ml.Enabled = False
            cval = 1
            
        Case "WCA"  '2
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            F2_WCA.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8b_wc_staff1.List() = ws_lists.Range("U17:U24").Value
            Me.uf8b_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8b_commby.List() = ws_lists.Range("U17:U29").Value
            cval = 1
            
        Case "WCO"  '3
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            F3_WCO.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8c_wc_staff1.List() = ws_lists.Range("U17:U24").Value
            Me.uf8c_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8c_commby.List() = ws_lists.Range("U17:U29").Value
            cval = 1
            
        Case "CCF"  '4
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            F4_CCF.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8d_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8d_commto.List() = ws_lists.Range("U17:U29").Value
            Me.cb_dcm_ml.Enabled = False
            cval = 1
            
        Case "CCA"  '5
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            With F5_CCA
                .Visible = True
                .Top = 6
                .Left = 6
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8e_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8e_commto.List() = ws_lists.Range("U17:U29").Value
            Me.cb_ecm_ml.Enabled = False
            cval = 1
            
        Case "CCO"  '6 
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            F6_CCO.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            Me.uf8f_rationale.List() = ws_lists.Range("CZ1:CZ3").Value
            Me.uf8f_commto.List() = ws_lists.Range("U17:U29").Value
            Me.cb_fcm_ml.Enabled = False
            cval = 1
            
        Case "PTD"  '7
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 216
            F7_PTD.Visible = True
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            RID = uf8_post.uf8_prin & uf8_post.uf8_rin
            Me.uf8g_pstime = format(Application.WorksheetFunction.VLookup(RID, ws_psttemp.Range("A:H"), 7, False), "h:mm AM/PM")
            Me.uf8g_petime = format(Application.WorksheetFunction.VLookup(RID, ws_psttemp.Range("A:H"), 8, False), "h:mm AM/PM")
            Me.uf8g_pstime.Locked = True
            Me.uf8g_petime.Locked = True
            uf8g_apetime.Enabled = False
            Me.uf8g_s_minsdev = format(TimeValue(Me.uf8g_pstime) - TimeValue(Me.uf8g_pstime), "0.00")
            Me.uf8g_e_minsdev = format(TimeValue(Me.uf8g_petime) - TimeValue(Me.uf8g_petime), "0.00")
            Me.uf8g_net_minsdev = format(CInt(uf8g_e_minsdev) + CInt(uf8g_s_minsdev), "0.00")
            Me.uf8g_s_minsdev.Locked = True
            Me.uf8g_e_minsdev.Locked = True
            Me.uf8g_net_minsdev.Locked = True
            cval = 1
            
        Case "PAD"  '8
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 216
            F8_PAD.Visible = True
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            RID = uf8_post.uf8_prin & uf8_post.uf8_rin
            Me.uf8h_bookedact = Application.WorksheetFunction.VLookup(RID, ws_psttemp.Range("A:H"), 7, False)
            cval = 1
            
        Case "CNS"  '9
            uf8b_postcomm.Width = 248
            uf8b_postcomm.Height = 303
            With F9_CNS
                .Visible = True
                .Top = 6
                .Left = 6
            End With
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            cval = 1
            
        Case "CNR"  '10
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 502
            With F10_CNR
                .Visible = True
                .Top = 6
                .Left = 6
            End With
            With uf8b_cancel
                .Top = 450
                .Left = 6
            End With
            With uf8b_submit
                .Top = 450
                .Left = 168
            End With
            cval = 1
            
        Case "DEL"  '11
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 324
            F11_DEL.Visible = True
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
            cval = 1
            
        Case "CRQ"  '12
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 216
            F12_CRQ.Visible = True
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            cval = 1
            
        Case "WCT"  '13
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 216
            F13_WCT.Visible = True
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            cval = 1
            
        Case Else 'CT
            uf8b_postcomm.Width = 238
            uf8b_postcomm.Height = 216
            F14_CCT.Visible = True
            With uf8b_cancel
                .Top = 168
                .Left = 6
            End With
            With uf8b_submit
                .Top = 168
                .Left = 168
            End With
            cval = 1
    End Select

End Sub

I am having trouble diagnosing the cause of the "Case without Select Case" Error that I am receiving with the line highlighted in red.

Thoughts?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
In the previous case you have 3 Withs, but only 2 end withs, that's what's causing the error.
Code:
            With F5_CCA
                .Visible = True
                .Top = 6
                .Left = 6
            With uf8b_cancel
                .Top = 270
                .Left = 6
            End With
            With uf8b_submit
                .Top = 270
                .Left = 168
            End With
 
Last edited:
Upvote 0
Ah ... that's it Fluff. Thanks, I just needed that second set of eyes.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,530
Messages
6,120,071
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top