Setting worksheet name to variable doesn't work

mark hansen

Well-known Member
Joined
Mar 6, 2006
Messages
534
Office Version
  1. 2016
Platform
  1. Windows
I have the following code that seemed to stop working...

Dim ws, bf As Worksheet

'On Error GoTo ErrHandler
Set ws = Sheets(8)
Set bf = Sheets(9)

When I step through it (F8) I get a Error 9 Subscript out of range. The code is on sheet 8 and I want to set WS as sheet 8 and BF as sheet 9.

What could cause this to stop working. It was working when I wrote and stepped through it before?

Thanks,
Mark
 
Thanks everyone, I appreciate the input. Preliminary testing has the Sheet8 working well. This is a big help and will go along way, most of all, it added to my foundation and explained the difference between sheet8 and sheets(8). It also explained what sheets(8) worked one time, but not after I deleted worksheets.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,504
Messages
6,125,183
Members
449,212
Latest member
kenmaldonado

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