ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Button does not work on second click (https://www.excelbanter.com/excel-programming/345186-macro-button-does-not-work-second-click.html)

retseort[_7_]

Macro Button does not work on second click
 

I have button1 assigned ot the following macro on the 'headerpage'
worksheet of my workbook. When the button is clicked it makes the
'Instruction' worksheet visible and active.

Sub hide_sheet()
'
Static fOn As Boolean

fOn = Not fOn
Sheets("Instructions").Visible = True = fOn
Sheets("Instructions").Select
End Sub


On the 'Instruction' worksheet I have button2 with the following code.
THis takes the user back to the 'headerpage' worksheet and rehides the
'instruction' worksheet.

Sub hide_instruction2()
'

Static fOff As Boolean
Sheets("HeaderPage").Select
fOn = Not fOn
Sheets("Instructions").Visible = False = fOn
End Sub


THE ISSUE

When youy click on button1 for the first time it works fine, then click
on button to and it indeed does take the user back to the 'headerpage'
worksheet and rehides the 'instruction' worksheet.

However, if I click on button1 again it gives me a 'runtime error 1004'
and highlights the line 'Sheets("Instructions").Select' in the Sub
hide_sheet() macro assigned to button 1.

Why? and how do I get this to work so no matter howmany times the user
wants to switch back and forth between the two pages it will allow them
to?

Thanks
Dan


--
retseort
------------------------------------------------------------------------
retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690
View this thread: http://www.excelforum.com/showthread...hreadid=483613


Toppers

Macro Button does not work on second click
 
Hi,
Unless (and I may have!) I misunderstand what you want, the
following "flips" between the worksheets - "Headerpage" is ALWAYS visible(?)

Sub hide_sheet()
Sheets("Instructions").Visible = True
Sheets("Instructions").Select
End Sub

Sub hide_instruction2()
Sheets("HeaderPage").Select
Sheets("Instructions").Visible = False
End Sub


HTH
"retseort" wrote:


I have button1 assigned ot the following macro on the 'headerpage'
worksheet of my workbook. When the button is clicked it makes the
'Instruction' worksheet visible and active.

Sub hide_sheet()
'
Static fOn As Boolean

fOn = Not fOn
Sheets("Instructions").Visible = True = fOn
Sheets("Instructions").Select
End Sub


On the 'Instruction' worksheet I have button2 with the following code.
THis takes the user back to the 'headerpage' worksheet and rehides the
'instruction' worksheet.

Sub hide_instruction2()
'

Static fOff As Boolean
Sheets("HeaderPage").Select
fOn = Not fOn
Sheets("Instructions").Visible = False = fOn
End Sub


THE ISSUE

When youy click on button1 for the first time it works fine, then click
on button to and it indeed does take the user back to the 'headerpage'
worksheet and rehides the 'instruction' worksheet.

However, if I click on button1 again it gives me a 'runtime error 1004'
and highlights the line 'Sheets("Instructions").Select' in the Sub
hide_sheet() macro assigned to button 1.

Why? and how do I get this to work so no matter howmany times the user
wants to switch back and forth between the two pages it will allow them
to?

Thanks
Dan


--
retseort
------------------------------------------------------------------------
retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690
View this thread: http://www.excelforum.com/showthread...hreadid=483613



retseort[_9_]

Macro Button does not work on second click
 

You were correct and your code offering worked great...you are truly a
GREAT ONE.

THANKS

:) :) :) :)


--
retseort
------------------------------------------------------------------------
retseort's Profile: http://www.excelforum.com/member.php...o&userid=24690
View this thread: http://www.excelforum.com/showthread...hreadid=483613



All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com