Excel file crashes when setting variable to Sheet1

SkywardPalm

Board Regular
Joined
Oct 23, 2021
Messages
61
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub Sheet_Select()

    Dim sht As Worksheet
    
    
    'select Macro Controls Sheet
    
    Set sht = Sheet1
    sht.Select

My excel file crashes when the macro runs (on Set sht), but only on certain devices. It doesn't throw any errors and tries to re-open in safe mode. Any advice would be greatly appreciated.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Have you used the variable sht anywhere else?

Have you tried renaming the variable to say 'ws'?
 
Upvote 1
Solution
Have you used the variable sht anywhere else?

Have you tried renaming the variable to say 'ws'?

So changing the name worked.. I am using the variable in other modules but none of them are global variables. What could be causing this exactly?
 
Upvote 0
I was guessing that 'sht' had been used for something else like the name of a userform or the name of a module etc.

It seemed to me as the code looks good that the problem was with 'sht' variable, it works my end with 'sht' and thats why i came to that conclusion.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,617
Latest member
Narendra Babu D

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