Select case not working

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

Please can someone help me understand why this code for a select case isn't working, it's skipping straight to the Case Else line - the worksheets with the case names do exist in the workbook as they have been created by another macro and the cases match too:
Code:
Sub CountRows()
Dim ws As Worksheet
For Each ws In Worksheets
    Select Case ws.Name
        Case "Remaining", "No_Break", "Listed_Instruments", "Net_Zero_Difference", _
                "One_Dodge_Many_FO", "Many_Dodge_One_FO"
            If IsEmpty(Range("A3")) Then
                Range("A1").Value = "No breaks"
            Else
                Range("A1").Value = Range("A2").End(xlDown).Row - 2
            End If
        Case Else
    End Select
Next ws
End Sub

Thank you,
Jack
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I know exactly what I did wrong and was just about to remove this post!
Basically I wasn't specifying each worksheet to check if A3 is empty or not so it was checking A3 in whatever the activesheet is without adjusting for the next sheet - no worries, problem solved!
 
Upvote 0
Select Case is "Case Sensitve". So, "Remaining" is not the same as "REMAINING". I would normally use
Code:
Select Case UCase(ws.Name)
Case "REMAINING","NO_BREAK",'etc

lenze
 
Upvote 0
Cheers Lenze, fortunately this time the cases did all match, just a oversight in my part on what value was being (incorrectly) valued in the IF statement, but good to know for next time!
 
Upvote 0
You also don't need the Case Else as you are not executing any code under this.
 
Upvote 0
Thanks HotPepper, I think I had something there before that I decided I didn't need but didn't delete the case else part out.
Cheers,
J
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,004
Members
449,203
Latest member
Daymo66

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