Select Case Issue

KerryFSA

New Member
Joined
Dec 5, 2018
Messages
49
In general, is/are there condition(s) in which Excel VBA will not recognize a "Select Case" statement? My current project is failing to compile (Error: Case without Select Case)) even though "Select Case" is obviously in the code just above the first case. (It is not within another Select Case block.)
Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If it's a compile error then either the syntax or structure of your code is wrong. I've often code fail to compile because of a simple typo.

If you post your code there's a good chance we can fix it.
 
Upvote 0
This code will generate that error:

Code:
Sub KFSA()
  Select Case Range("A1").Value
    Case "Bob"
    If Range("B1") = "Joe" Then
      Case "Jim"
      ' ...
    End If
  End Select
End Sub

See the problem?
 
Upvote 0
Along with the If statement shown by shg

Loops & with statements can cause the same problem
 
Upvote 0
The first thing that occurred to me was a looping error as per shg.
I've since transferred the project back to my iMac from my PC and the Case problem has disappeared, only to be replaced by the Sort problem described in another thread. Go figure.

Thanks for your replies. njimack - if problem recurs, I will post code.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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