Code won't run for hidden sheet

Reset

Board Regular
Joined
Apr 16, 2010
Messages
227
I want to hide a sheet that holds raw data for crunching so the user can't easily click on it. However, when I run code I get "Run-time error '1004': Select method of Worksheet class failed". Is there a way to hide the sheet and still allow code to call it up?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You can't select a hidden sheet, but you can operate on its contents without selecting, e.g.,

Code:
With Worksheets("myHiddenSheet")
    .Range("A1").Value = 1
End with
Post some code if you need help
 
Upvote 0
It is generally recommended to avoid using select method while it dramatically slows down performance.

although sometimes painful, .select can almost always be avoided (unless you really want to select)
 
Upvote 0
Darn. I did try this:
Code:
Sheets("Sheet4").Visible = True
'run needed code
Sheets("Sheet4").Visible = False
works ok but you get screen blinks while it executes. How about a way to keep it visible but the user cannot select it or at least change anything on it and still run code?
Thanks so far.
 
Upvote 0
Either use, worksheet protect option as it is available in Excel

Or suppose if you have to protect Sheet1 and block the user only then use something like:
Code:
Private Sub Workbook_Open()
Sheets("Sheet1").Protect Userinterfaceonly = True
End Sub
Note: You can change the data on this sheet programmatically.
 
Upvote 0
Taurean,

I tried your code and it did not recognize "Userinterfaceonly". I took that out and got back to the original issue, but now the sheet was protected and I could not unprotect. Manually protecting the sheet won't allow changes either.
 
Upvote 0
That is very strange. Create a new workbook and then its ThisWorkbook Module insert following code:

Code:
Private Sub Workbook_Open()
'Run this first!
Sheets(1).Protect UserInterfaceOnly:=True
End Sub

Sub Test()
'Run this code after running code to protect userinterface.
Sheets(1).Range("D1").Value = "Somebody"
End Sub

Sub Test2()
'To unprotect sheet protected above!
Sheets(1).Unprotect
End Sub

And then test them one by one. Let me know if you still have difficulty.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
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