Frank M
Frank M

Reputation: 83

Why am I am getting an else error when I use a select case statement & how do I fix it?

I modified code that I use to call multiple worksheets, & I would like to use it for calling web addresses.

Sub OVR_Office_Listing()
  Dim i As String

'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data Entry"
i = MsgBox("Continue to OVR Office Directory?", vbYesNo, " Referral Workbook - Data Entry")

If Not i = vbYes Then Exit Sub

'First message shows in the body of the box, message 2 shows at the top of the box.
Do
    MyValue = Application.InputBox("Only Click Ok or Cancel after your Selection!!!!!!!" & vbCrLf & _
                           "1 = OVR Office Directory" & vbCrLf & _
                           "2 = BBVS (Bureau of Blindness & Visual Services)Office Directory", "Walk In Training Data Entry")
    ' Sub messaage box exit.
    If MyValue = False Then
        Exit Sub
    ElseIf (MyValue = 1) Or (MyValue = 2) Then
        Exit Do
    Else
        MsgBox "You have not made a valid entry.  Please try again.", vbInformation, "Referral Workbook - Data Entry"
    End If
Loop    'Code to Execute When Condition = value_1

Select Case MyValue
    Case 1
           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on OVR Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                Else
                Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
ie.Visible = True
End Select
                End If
    'Code to Execute When Condition = value_2
    Case 2

           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                Else
                  Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/individuals/disability-services/ovr/pages/OVR-office-directory.aspx"
ie.Visible = True
End Select

                End If
End Select
End Sub

I get a compile error: Else with out if. The error occurs at the following lication: Case 1 ' The message below only shows when you are on the active sheet. MsgBox "You are already on OVR Office Directory!", vbInformation, "Referral Workbook - Data Entry" Else On else. Is it possible to do what I am attempting, and what am I missing. I do have a Select Case MyValue, and it appears that it is not enough or in the wrong location. Please tell me what I am doing wrong.

Upvotes: 0

Views: 64

Answers (3)

Frank M
Frank M

Reputation: 83

Problems solved.

      `Sub OVR_Office_Listing()
      Dim i As String
     'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data  Entry"
     i = MsgBox("Continue to OVR Directories?", vbYesNo, " Referral Workbook - Data Entry")

   If Not i = vbYes Then Exit Sub

   'First message shows in the body of the box, message 2 shows at the top of the box.

   Do
   MyValue = Application.InputBox("Only Click Ok or Cancel after your  Selection!!!!!!!" & vbCrLf & _
                       "1 = OVR Office Directory" & vbCrLf & _
                       "2 = BBVS (Bureau of Blindness & Visual Services)    Office Directory", "Walk In Training Data Entry")
 'Sub messaage box exit.
 If MyValue = False Then
    Exit Sub
 ElseIf (MyValue = 1) Or (MyValue = 2) Then
    Exit Do
 Else
 MsgBox "You have not made a valid entry.  Please try again.",  vbInformation, "Referral Workbook - Data Entry"
 End If

 Loop
'Code to Execute When Condition = value_1
Select Case MyValue
Case 1
'Message prior to calling the webb address.
                MsgBox "Please wait, while get you the OVR web address.", vbInformation, "Referral Workbook - Data Entry"

            Dim ie As Object
Set ie1 = CreateObject("INTERNETEXPLORER.APPLICATION")
ie1.NAVIGATE "http://www.dli.pa.gov/individuals/disability- services/ovr/pages/OVR-office-directory.aspx"
ie1.Visible = True
 'Code to Execute When Condition = value_2
Select Case MyValue
 End Select
 Case 2

       'Message prior to calling the webb address.
                MsgBox "Please wait, while I get you the Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
            'Else
              Dim ie2 As Object
  Set ie2 = CreateObject("INTERNETEXPLORER.APPLICATION")
  ie2.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
  ie2.Visible = True
  End Select
 End Sub`

Upvotes: 1

Harish Kumar Garg
Harish Kumar Garg

Reputation: 39

try to use below code.

Sub OVR_Office_Listing()
  Dim i As String

'MsgBox prompt:="1st 6 Months of Reports?", Title:="Referral Workbook - Data Entry"
i = MsgBox("Continue to OVR Office Directory?", vbYesNo, " Referral Workbook - Data Entry")

If Not i = vbYes Then Exit Sub

'First message shows in the body of the box, message 2 shows at the top of the box.
Do
    MyValue = Application.InputBox("Only Click Ok or Cancel after your Selection!!!!!!!" & vbCrLf & _
                           "1 = OVR Office Directory" & vbCrLf & _
                           "2 = BBVS (Bureau of Blindness & Visual Services)Office Directory", "Walk In Training Data Entry")
    ' Sub messaage box exit.
    If MyValue = False Then
        Exit Sub
    ElseIf (MyValue = 1) Or (MyValue = 2) Then
        Exit Do
    Else
        MsgBox "You have not made a valid entry.  Please try again.", vbInformation, "Referral Workbook - Data Entry"
    End If
Loop    'Code to Execute When Condition = value_1

Select Case MyValue
    Case 1
           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on OVR Office Directory!", vbInformation, "Referral Workbook - Data Entry"
    Case 2
                Dim ie As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie.NAVIGATE "http://www.dli.pa.gov/Individuals/Disability-Services/bbvs/Pages/BBVS-Office-Directory.aspx"
ie.Visible = True
'End Select
                'End If
    'Code to Execute When Condition = value_2
    Case 3

           ' The message below only shows when you are on the active sheet.
                    MsgBox "You are already on Bureau of Blindness & Visual Services Office Directory!", vbInformation, "Referral Workbook - Data Entry"
                'Else
                  Dim ie2 As Object
Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
ie2.NAVIGATE "http://www.dli.pa.gov/individuals/disability-services/ovr/pages/OVR-office-directory.aspx"
ie2.Visible = True
End Select

Upvotes: 0

braX
braX

Reputation: 11755

Change that Else to Case Else. Else by itself requires a matching If statement.

Upvotes: 0

Related Questions