Runtime Error 9 Subscript out of Range

klyhthwy

New Member
Joined
Jul 13, 2011
Messages
14
Private Sub EditOpen()
Dim book As Workbook
Dim sheet As Worksheet

For Each book In Workbooks
If Not book.ReadOnly Then

Set sheet = book.Worksheets("Operating")

sheet.Range("$K$13:$K$18,$K$21:$K$26,$K$29:$K$34,$K$37:$K$42,$K$45:$K$50,$K$53:$K$58,$K$61:$K$66,$K$69:$K$74,$K$77:$K$82,$K$85:$K$90,$K$93:$K$98,$K$101:$K$106").Locked = False

Set sheet = Nothing
End If
Next
End Sub

When I run this code I get a run-time error 9: "Subscript out of Range". Can anyone tell me what my problem is?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I have checked this over and over. It does.

If I use a For loop as follows

For Each sheet In book.Worksheets

If sheet.Name = "Operating" Then
sheet...
End If
Next

I have no problem. It is only when I use Set sheet = ...
That is doesn't work.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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