Run-time error '13': Type Mismatch when hiding rows via VBA

Sky188

New Member
Joined
Nov 16, 2017
Messages
7
I'm building a custom price list for each state, but rather than always have 50+ worksheets showing I only want those showing that are going to be used. To filter the visible worksheets, I'm using checkboxes on an intro page to change values in column A, then running a VBA macro to hide/unhide worksheet names based on those column A values. This works great for the most part, but I'm running into a run-time error '13' anytime I try to unhide two worksheets that are next to one another. Each can hide/unhide individually, or with any other worksheet that isn't immediately next to it. I initially though separating the column A values might fix it, but it didn't.

Any ideas on why this error would be happening or how to fix it?

VBA Code:
Sub Arizona()
Dim HideSheet As Boolean
HideSheet = Range("A8")

If HideSheet Then
    Sheets("Arizona").Visible = True
    Else
    Sheets("Arizona").Visible = False
    End If
End Sub

VBA Code:
Sub Arkansas()
Dim HideSheet As Boolean
HideSheet = Range("A10")

If HideSheet Then
    Sheets("Arkansas").Visible = True
    Else
    Sheets("Arkansas").Visible = False
    End If
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Which line of code causes the error? When the error occurs what are the values in A8 and A10? Maybe you are trying to assign a non-Boolean value to HideSheet.
 
Upvote 0
Which line of code causes the error? When the error occurs what are the values in A8 and A10? Maybe you are trying to assign a non-Boolean value to HideSheet.
The values is column A are true/false based on the state checkboxes being checked or not. When the error occurs, the values are true. It works great if non consecutive cells are true and only errors when two consecutive cells in column A are true.
 
Upvote 0
You should specify a worksheet for the ranges.
 
Upvote 1
Solution

Forum statistics

Threads
1,214,584
Messages
6,120,384
Members
448,956
Latest member
JPav

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