Case without case select and else without if error

alxn

New Member
Joined
Jul 17, 2023
Messages
14
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hey,

I am getting some errors running this piece of code, I keep getting a case without case select and another if error. I've gone trough and changed a few things but the error is still ongoing. Any help would be good thank you.

VBA Code:
Case "Group 2"
                If Day(DOH + 60) = 1 Then
                    If class = "Class 1" Then
                        GracePeriod = DOH + 60
                    Else
                    GracePeriod = Application.EoMonth(DOH + 60, 0) - 0
                    If class = "Class 2" Then
                        GracePeriod = DOH + 30
                End If
         
         Case "Group1", "1"
            If Day(DOH + 60) = 1 Then
                If class = "F Class" Then
                    GracePeriod = DOH + 60
                Else
                    GracePeriod = Application.EoMonth(DOH + 60, 0) - 44
                ElseIf class = "S Class" Then
                    If Day(DOH + 30) = 1 Then
                        GracePeriod = DOH + 30
                    Else
                        GracePeriod = Application.EoMonth(DOH + 30, 0) - 0
                    End If
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
The error message is a bit of a red herring. The issue is actually with your If statements.
The number of "End If" statements does not match your "If" statements.

In the first block alone:
Rich (BB code):
                If Day(DOH + 60) = 1 Then
                    If class = "Class 1" Then
                        GracePeriod = DOH + 60
                    Else
                    GracePeriod = Application.EoMonth(DOH + 60, 0) - 0
                    If class = "Class 2" Then
                        GracePeriod = DOH + 30
                End If
Unless you do the THEN block on the same line as the IF block, i.e.
If something Then something else
every "If" needs a corresponding "End If".
 
Upvote 0
The error message is a bit of a red herring. The issue is actually with your If statements.
The number of "End If" statements does not match your "If" statements.

In the first block alone:
Rich (BB code):
                If Day(DOH + 60) = 1 Then
                    If class = "Class 1" Then
                        GracePeriod = DOH + 60
                    Else
                    GracePeriod = Application.EoMonth(DOH + 60, 0) - 0
                    If class = "Class 2" Then
                        GracePeriod = DOH + 30
                End If
Unless you do the THEN block on the same line as the IF block, i.e.
If something Then something else
every "If" needs a corresponding "End If".
Hey, I apologize for the late response, but I am still getting the same error with this input.
 
Upvote 0
Hey, I apologize for the late response, but I am still getting the same error with this input.
Note what I gave you is just one example. You have to correct each/all of your Case blocks.
The total number if "IF" statements should match the total number of "END IF" statements.

After you have made ALL the updates, if you are still having issues, please post your updated code.
I cannot tell what might still be wrong if I don't see your updated code.
 
Upvote 0

Forum statistics

Threads
1,215,159
Messages
6,123,348
Members
449,097
Latest member
thnirmitha

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