Error 13 Type Mismatch - VBA suddenly stopped working

John Sadler

New Member
Joined
May 1, 2012
Messages
48
Hi folks ... the code below was working but suddenly stopped with Error 13 Type Mismatch where 'If ws.Range("U1") = "Active" And ws.Range("U2") = "Outbound" Then' was highlighted as the problem. If I remove 'And ws.Range("U2") = "Outbound" ' it will show all sheets where U1 = Active.

So was working but not now

Sub HideOutboundSheets()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In Worksheets
If ws.Range("U1") = "Active" And ws.Range("U2") = "Outbound" Then
ws.Visible = False
End If
Next ws
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe this

Code:
Sub HideOutboundSheets()
Application.ScreenUpdating = False
Dim ws As Worksheet
For Each ws In Worksheets
    With ws
        If .Range("U1") = "Active" And .Range("U2") = "Outbound" Then
            .Visible = False
        End If
End With
Next ws
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Do you have one of the sheets protected ???
 
Upvote 0
Hi Michael ... no protected sheets but your suggestion got me looking at the cell values and I found 2 old sheets where the cell values seemed to be causing the error.
So .. all good now.
Thanks for making me look harder at the sheets.
Cheers John
 
Upvote 0
Haha.....always seems to happen when playing with multiple sheets.....you get focused on Sheet1 and the others get overlooked...:beerchug:
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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