macro fails after enabling

Peterfc2

Active Member
Joined
Jan 2, 2004
Messages
392
Office Version
  1. 2013
Platform
  1. Windows
I have a workbook I get from my website. When I save it and enable it gives an error in the macro.

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sht As Object
For Each sht In Sheets

Fails at this line

Anyone any ideas?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,067
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try":
Dim sht as Worksheet
For each sht in Thisworkbook.Worksheets
 
Last edited:
Upvote 0

Peterfc2

Active Member
Joined
Jan 2, 2004
Messages
392
Office Version
  1. 2013
Platform
  1. Windows
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sht As Object
For Each sht In ThisWorkbook.Worksheets
If sht.Name <> "INDEX" Then
sht.Visible = xlSheetHidden
End If
Next sht
Sheets("INDEX").Select

Now it stops here
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,587
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
You didn't use the Dim for worksheets as suggested by Joe !!
Why not simply post the entire code !
That way we can debug it live !!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,190,741
Messages
5,982,692
Members
439,790
Latest member
jonaust

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
Top