macro fails after enabling

Peterfc2

Active Member
Joined
Jan 2, 2004
Messages
394
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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try":
Dim sht as Worksheet
For each sht in Thisworkbook.Worksheets
 
Last edited:
Upvote 0
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
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,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

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