PDA

View Full Version : Solved: Hidden Worksheet and Macros



zoom38
02-11-2006, 08:02 AM
I have a worksheet called "Tables" where there is no user input whatsoever. All of the operations on this worksheet are done by formula and macros. I protected the worksheet and entered "ActiveSheet.Protect UserInterfaceOnly:=True". This worked great. Next I tried hiding the "Tables" worksheet then activated the macro but I get a "Run-Time Error '1004': Select method of worksheet class failed." message. I selected debug and it took me to my main module which sets the "Tables" worksheet as active and calls a macro on this sheet. The debugger highlights the
"Sheets("Tables").Select" line.
Anyone have any ideas on how to fix this?

Thanks
Gary

Public Sub Main()
Dim rngStart As Range
Set rngStart = Selection

Sheets("Tables").Select
First_Shift_Sort
Flex_Shift_Sort
Second_Shift_Sort
SD_Sort

With rngStart
.Parent.Activate
.Select
End With
End Sub

mdmackillop
02-11-2006, 08:08 AM
Hi Gary,
Try Sheets("Tables").Activate instead

zoom38
02-11-2006, 09:43 AM
Thanks MD that seems to work. One other thing, when I activate the macro the hidden sheet splashes on the screen. Can that be avoided?

Thanks
Gary

mdmackillop
02-11-2006, 09:46 AM
Try adding Application.ScreenUpdating = False at the head of your code and Application.ScreenUpdating = True before it closes

zoom38
02-11-2006, 09:59 AM
Thanks MD you solved this thread. Both of you're replies were on the money and worked excellent. Thanks for the quick response.

Thanks
Gary

mdmackillop
02-11-2006, 10:08 AM
Glad to help.
Just for info, you should always Activate sheets, not select them.
With cells, code can read/write cells without selecting them, which speeds up code execution considerably.