Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Help with some simple code

Hi There,
I was given the following code to ensure that whenever a workbook is opened
it will always go to Sheet1 and A1. This was great:

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I'm now requiring something similar to ensure that if any other sheets are
selected once the workbook is opened, the command [Range("A1").Select]
occurs.So, could someone help me with the first part of the code. I assume
you would go into the code viewer for each sheet and add something like:
Sheet1_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I think I tried this but a compile error when I opened up the workbook.
Hope someone can help (something tells me I could put some code in a module
so that I wan't have to repeat it for each sheet. However, happy to just get
the basic code to put in if that is not viable)

Hope someone can help
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Help with some simple code

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Range("A1").Select
End Sub


--
HTH

Bob Phillips

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

"Angeline" wrote in message
...
Hi There,
I was given the following code to ensure that whenever a workbook is

opened
it will always go to Sheet1 and A1. This was great:

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I'm now requiring something similar to ensure that if any other sheets are
selected once the workbook is opened, the command [Range("A1").Select]
occurs.So, could someone help me with the first part of the code. I assume
you would go into the code viewer for each sheet and add something like:
Sheet1_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I think I tried this but a compile error when I opened up the workbook.
Hope someone can help (something tells me I could put some code in a

module
so that I wan't have to repeat it for each sheet. However, happy to just

get
the basic code to put in if that is not viable)

Hope someone can help



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default Help with some simple code

Hi Bob,
Thanks for this. I tried it however and it did not seem to work. I inserted
the code into the VB Editor for each sheet and saved. To test it I scrolled
down on a number of the sheets, saved & closed. Upon opening up the workbook
and clicking the said sheets, they remained scrolled down as I had left them.
Could I be doing something wrong?

Thanks

"Bob Phillips" wrote:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Range("A1").Select
End Sub


--
HTH

Bob Phillips

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

"Angeline" wrote in message
...
Hi There,
I was given the following code to ensure that whenever a workbook is

opened
it will always go to Sheet1 and A1. This was great:

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I'm now requiring something similar to ensure that if any other sheets are
selected once the workbook is opened, the command [Range("A1").Select]
occurs.So, could someone help me with the first part of the code. I assume
you would go into the code viewer for each sheet and add something like:
Sheet1_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I think I tried this but a compile error when I opened up the workbook.
Hope someone can help (something tells me I could put some code in a

module
so that I wan't have to repeat it for each sheet. However, happy to just

get
the basic code to put in if that is not viable)

Hope someone can help




  #4   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Help with some simple code

Bob's code should go in the ThisWorkbook module, not each sheet module.



"Angeline" wrote:

Hi Bob,
Thanks for this. I tried it however and it did not seem to work. I inserted
the code into the VB Editor for each sheet and saved. To test it I scrolled
down on a number of the sheets, saved & closed. Upon opening up the workbook
and clicking the said sheets, they remained scrolled down as I had left them.
Could I be doing something wrong?

Thanks

"Bob Phillips" wrote:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Range("A1").Select
End Sub


--
HTH

Bob Phillips

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

"Angeline" wrote in message
...
Hi There,
I was given the following code to ensure that whenever a workbook is

opened
it will always go to Sheet1 and A1. This was great:

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I'm now requiring something similar to ensure that if any other sheets are
selected once the workbook is opened, the command [Range("A1").Select]
occurs.So, could someone help me with the first part of the code. I assume
you would go into the code viewer for each sheet and add something like:
Sheet1_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I think I tried this but a compile error when I opened up the workbook.
Hope someone can help (something tells me I could put some code in a

module
so that I wan't have to repeat it for each sheet. However, happy to just

get
the basic code to put in if that is not viable)

Hope someone can help




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Help with some simple code

Add the code to the same module as your Workbook_Open code.

--
HTH

Bob Phillips

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

"Angeline" wrote in message
...
Hi Bob,
Thanks for this. I tried it however and it did not seem to work. I

inserted
the code into the VB Editor for each sheet and saved. To test it I

scrolled
down on a number of the sheets, saved & closed. Upon opening up the

workbook
and clicking the said sheets, they remained scrolled down as I had left

them.
Could I be doing something wrong?

Thanks

"Bob Phillips" wrote:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Range("A1").Select
End Sub


--
HTH

Bob Phillips

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

"Angeline" wrote in message
...
Hi There,
I was given the following code to ensure that whenever a workbook is

opened
it will always go to Sheet1 and A1. This was great:

Private Sub Workbook_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I'm now requiring something similar to ensure that if any other sheets

are
selected once the workbook is opened, the command [Range("A1").Select]
occurs.So, could someone help me with the first part of the code. I

assume
you would go into the code viewer for each sheet and add something

like:
Sheet1_Open()
Sheets("Sheet1").Select
Range("A1").Select
End Sub

I think I tried this but a compile error when I opened up the

workbook.
Hope someone can help (something tells me I could put some code in a

module
so that I wan't have to repeat it for each sheet. However, happy to

just
get
the basic code to put in if that is not viable)

Hope someone can help






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
Simple Checkbox Message Code nemadrias Excel Discussion (Misc queries) 10 June 21st 06 08:59 PM
code not unique find latest date Barbara Wiseman Excel Discussion (Misc queries) 3 December 11th 05 08:50 AM
VLOOKUP for Zip Code Ranges JerseyJR Excel Worksheet Functions 2 September 6th 05 06:37 PM
Conform a total to a list of results? xmaveric Excel Discussion (Misc queries) 1 August 21st 05 07:22 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM


All times are GMT +1. The time now is 02:12 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"