Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Macro Error When Connecting to Hidden Sheet

I have a very simple macro that, when run, takes the user to a specified
location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is visible, but
when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination sheet
is hidden?

Thanks in advance!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro Error When Connecting to Hidden Sheet

Unhide the sheet first.

You could even hide what you're doing from the user:

Sub ToProjectInfoPage()
application.screenupdating = false
with Sheets("Project Info")
.visible = xlsheetvisible
.Select
.Range("A1:E1").Select
.visible = xlsheethidden
end with
application.screenupdating = true
End Sub

But there are not that many things that would require you to select a range.

Maybe you can just work on that range directly.



Wuddus wrote:

I have a very simple macro that, when run, takes the user to a specified
location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is visible, but
when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination sheet
is hidden?

Thanks in advance!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 459
Default Macro Error When Connecting to Hidden Sheet

Wuddus wrote:
I have a very simple macro that, when run, takes the user to a
specified location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is
visible, but when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination
sheet is hidden?

Thanks in advance!



Hi Wuddus,

the error raise because you cannot select an hidden sheet and also you
cannot select a range on an hidden sheet...

So you can modify your macro in this way:

Sub ToProjectInfoPage()
With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
End with
End Sub

or if you don't want to make your sheet visible you can use this one:

Sub ToProjectInfoPage()

Application.ScreenUpdating = False

With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
'other code for calculations
End with

Application.ScreenUpdating = True

End Sub


--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 459
Default Macro Error When Connecting to Hidden Sheet

Franz Verga wrote:
Wuddus wrote:
I have a very simple macro that, when run, takes the user to a
specified location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is
visible, but when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination
sheet is hidden?

Thanks in advance!



Hi Wuddus,

the error raise because you cannot select an hidden sheet and also you
cannot select a range on an hidden sheet...

So you can modify your macro in this way:

Sub ToProjectInfoPage()
With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
End with
End Sub

or if you don't want to make your sheet visible you can use this one:

Sub ToProjectInfoPage()

Application.ScreenUpdating = False

With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
'other code for calculations
End with

Application.ScreenUpdating = True

End Sub


I forgot a line in both macro... You cannot select a range on a sheet
without selecting the sheet... So the macro should be:

Sub ToProjectInfoPage()
With Sheets("Project Info")
.Visible = xlSheetVisible
.Select
.Range("A1:E1").Select
End with
End Sub

if you want to see the previously hidden sheet, and:

Sub ToProjectInfoPage()

Application.ScreenUpdating = False

With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select

'other code for calculations

.Visible = xlSheetHidden

End with

Application.ScreenUpdating = True

End Sub


if you don't want show the hidden sheet.

Anyway, as also suggested from Dave, you can work on a range based on an
hidden sheet without selecting it...

--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Macro Error When Connecting to Hidden Sheet

Thanks, Dave. I think this will do the trick. Very helpful!

Sorry about the delayed response: I posted my question last night but then
didn't get a chance to log on until this morning.

"Dave Peterson" wrote:

Unhide the sheet first.

You could even hide what you're doing from the user:

Sub ToProjectInfoPage()
application.screenupdating = false
with Sheets("Project Info")
.visible = xlsheetvisible
.Select
.Range("A1:E1").Select
.visible = xlsheethidden
end with
application.screenupdating = true
End Sub

But there are not that many things that would require you to select a range.

Maybe you can just work on that range directly.



Wuddus wrote:

I have a very simple macro that, when run, takes the user to a specified
location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is visible, but
when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination sheet
is hidden?

Thanks in advance!


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 24
Default Macro Error When Connecting to Hidden Sheet

Thanks, Frank. Both your and Dave's responses, above, have been really
useful. (Perhaps I should just get more comfortable in VBA so I don't have to
ask dumb questions!)

"Franz Verga" wrote:

Franz Verga wrote:
Wuddus wrote:
I have a very simple macro that, when run, takes the user to a
specified location on another sheet in the same workbook:

Sub ToProjectInfoPage()
Sheets("Project Info").Select
Range("A1:E1").Select
End Sub

This works fine when the destination sheet ("Project Info") is
visible, but when it's hidden, the macro returns an error.

Is there a way to fix the macro so that it works when the destination
sheet is hidden?

Thanks in advance!



Hi Wuddus,

the error raise because you cannot select an hidden sheet and also you
cannot select a range on an hidden sheet...

So you can modify your macro in this way:

Sub ToProjectInfoPage()
With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
End with
End Sub

or if you don't want to make your sheet visible you can use this one:

Sub ToProjectInfoPage()

Application.ScreenUpdating = False

With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select
'other code for calculations
End with

Application.ScreenUpdating = True

End Sub


I forgot a line in both macro... You cannot select a range on a sheet
without selecting the sheet... So the macro should be:

Sub ToProjectInfoPage()
With Sheets("Project Info")
.Visible = xlSheetVisible
.Select
.Range("A1:E1").Select
End with
End Sub

if you want to see the previously hidden sheet, and:

Sub ToProjectInfoPage()

Application.ScreenUpdating = False

With Sheets("Project Info")
.Visible = xlSheetVisible
.Range("A1:E1").Select

'other code for calculations

.Visible = xlSheetHidden

End with

Application.ScreenUpdating = True

End Sub


if you don't want show the hidden sheet.

Anyway, as also suggested from Dave, you can work on a range based on an
hidden sheet without selecting it...

--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to change data in inactive sheet Diana Excel Discussion (Misc queries) 1 April 28th 06 08:36 PM
macro to change data in inactive sheet Diana Excel Discussion (Misc queries) 1 April 28th 06 08:10 PM
Macro to change data in a sheet Diana Excel Discussion (Misc queries) 1 April 28th 06 08:01 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Buttons to link to a hidden sheet tillytee1 Excel Discussion (Misc queries) 1 September 30th 05 12:29 PM


All times are GMT +1. The time now is 11:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"