Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro to remember sheet


Hi,

I have a macro (see below), but it doesn't work. When I click a button
on a custom made toolbar, the macro is triggered. It should remember
the sheet where the button was clicked and go to the sheet "Info". When
clicking again on this button it should get back to the remembered
sheet. I also have a button on the sheet "Info", with the macro
assigned. So by clicking the button on the sheet "Info", instead of
clicking the button on the toolbar, it should also get back to the
remembered sheet.
Can someone help me to get my macro to work? Thanks in advance!


Code:
--------------------
Sub InfoWerkbalk()

Const sht1 As String = "Begroting Calc Won"
Const sht2 As String = "Begroting WVB Won"
Const sht3 As String = "Werkelijk Uitv Won"
Const sht4 As String = "Totaaloverzicht Won"
Const sht5 As String = "Begroting Calc Uti"
Const sht6 As String = "Begroting WVB Uti"
Const sht7 As String = "Werkelijk Uitv Uti"
Const sht8 As String = "Totaaloverzicht Uti"
Const sht9 As String = "Info"

If ActiveSheet.Name = sht1 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht2 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht3 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht4 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht5 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht6 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht7 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht8 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht9 Then
Sheets(""" & Asheet & """).Select
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If

Info:
Sheets("Info").Select

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=569806

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default macro to remember sheet

Have you declared Asheet as a module level variable, i.e. before any macros?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"leonidas" wrote in
message ...

Hi,

I have a macro (see below), but it doesn't work. When I click a button
on a custom made toolbar, the macro is triggered. It should remember
the sheet where the button was clicked and go to the sheet "Info". When
clicking again on this button it should get back to the remembered
sheet. I also have a button on the sheet "Info", with the macro
assigned. So by clicking the button on the sheet "Info", instead of
clicking the button on the toolbar, it should also get back to the
remembered sheet.
Can someone help me to get my macro to work? Thanks in advance!


Code:
--------------------
Sub InfoWerkbalk()

Const sht1 As String = "Begroting Calc Won"
Const sht2 As String = "Begroting WVB Won"
Const sht3 As String = "Werkelijk Uitv Won"
Const sht4 As String = "Totaaloverzicht Won"
Const sht5 As String = "Begroting Calc Uti"
Const sht6 As String = "Begroting WVB Uti"
Const sht7 As String = "Werkelijk Uitv Uti"
Const sht8 As String = "Totaaloverzicht Uti"
Const sht9 As String = "Info"

If ActiveSheet.Name = sht1 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht2 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht3 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht4 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht5 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht6 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht7 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht8 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht9 Then
Sheets(""" & Asheet & """).Select
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If

Info:
Sheets("Info").Select

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:

http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=569806



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro to remember sheet


Hi Bob,

Sorry but I don't understand what you mean. I still am a novice with
VBA.
The macro as in my previous post is all I have. "Asheet" doesn't appear
anywhere else.
Can you tell me how to solve the problem?
Thanks again!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=569806

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default macro to remember sheet

Declare ASheet before the macro, like this

Dim Asheet As Variant

Sub InfoWerkbalk()

etc.



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"leonidas" wrote in
message ...

Hi Bob,

Sorry but I don't understand what you mean. I still am a novice with
VBA.
The macro as in my previous post is all I have. "Asheet" doesn't appear
anywhere else.
Can you tell me how to solve the problem?
Thanks again!


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:

http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=569806



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default macro to remember sheet

leonidas,


declare "Asheet " outside the sub, then the name with in Asheet will keep
the name when the macro stops.

So something like:

Dim Asheet As Variant
Sub InfoWerkbalk()

Const sht1 As String = "Begroting Calc Won"
Const sht2 As String = "Begroting WVB Won"
Const sht3 As String = "Werkelijk Uitv Won"
Const sht4 As String = "Totaaloverzicht Won"
Const sht5 As String = "Begroting Calc Uti"
Const sht6 As String = "Begroting WVB Uti"
Const sht7 As String = "Werkelijk Uitv Uti"
Const sht8 As String = "Totaaloverzicht Uti"
Const sht9 As String = "Info"

etc............

Met vriendelijke groet,
Rody Meulman




"leonidas" schreef
in bericht ...

Hi,

I have a macro (see below), but it doesn't work. When I click a button
on a custom made toolbar, the macro is triggered. It should remember
the sheet where the button was clicked and go to the sheet "Info". When
clicking again on this button it should get back to the remembered
sheet. I also have a button on the sheet "Info", with the macro
assigned. So by clicking the button on the sheet "Info", instead of
clicking the button on the toolbar, it should also get back to the
remembered sheet.
Can someone help me to get my macro to work? Thanks in advance!


Code:
--------------------
Sub InfoWerkbalk()

Const sht1 As String = "Begroting Calc Won"
Const sht2 As String = "Begroting WVB Won"
Const sht3 As String = "Werkelijk Uitv Won"
Const sht4 As String = "Totaaloverzicht Won"
Const sht5 As String = "Begroting Calc Uti"
Const sht6 As String = "Begroting WVB Uti"
Const sht7 As String = "Werkelijk Uitv Uti"
Const sht8 As String = "Totaaloverzicht Uti"
Const sht9 As String = "Info"

If ActiveSheet.Name = sht1 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht2 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht3 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht4 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht5 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht6 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht7 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht8 Then
Asheet = ActiveSheet.Name
GoTo Info
Else
If ActiveSheet.Name = sht9 Then
Sheets(""" & Asheet & """).Select
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If

Info:
Sheets("Info").Select

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile:
http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=569806





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
Annoying macro security wont remember my settings mark Stephens Excel Discussion (Misc queries) 1 May 22nd 09 05:19 PM
how to unproctect the sheet if password is not remember? how to decode the password if forget Excel Worksheet Functions 1 September 2nd 08 07:14 AM
I can't remember how to... ForSale[_56_] Excel Programming 5 June 14th 05 05:26 AM
Remember and add valeter New Users to Excel 2 April 13th 05 11:46 PM
Remember SelectionChange range in the Change sheet event? Marie J-son[_5_] Excel Programming 2 January 30th 05 09:40 AM


All times are GMT +1. The time now is 03:27 PM.

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"