Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Move to a specific cell when closing worksheet

Hi,
Hope this is an easy one for someone.
As a novice with VBA I could do with some help in adding code to a worksheet
that will automatically move the active cell back to being cell A1 before I
close my worksheet.
Any suggestions?
Thanks,
Dickie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Move to a specific cell when closing worksheet

Dickie,
You cannot close a worksheet, only a workbook. Put either of these in the
ThisWorkbook module:

If you mean for all worksheets:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WS As Worksheet

For Each WS In ThisWorkbook.Worksheets
WS.Select
WS.Range("A1").Activate
Next
'Return to the first WS if desired
ThisWorkbook.Worksheets(1).Select
End Sub

Or for only a specific WS:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook.Worksheets(1)
.Select
.Range("A1").Activate
End With
End Sub

NickHK

"Dickie Worton" wrote in message
...
Hi,
Hope this is an easy one for someone.
As a novice with VBA I could do with some help in adding code to a

worksheet
that will automatically move the active cell back to being cell A1 before

I
close my worksheet.
Any suggestions?
Thanks,
Dickie



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Move to a specific cell when closing worksheet

Dickie :

Paste this into the code for the worksheet.

(do that by right clicking there sheet tabe at the bottom and select view
code, then select thisworkbook and paste it in there).

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wn As Worksheet
Dim w As Worksheet
Set wn = ActiveSheet ' get current worksheet
For Each w In Worksheets
w.Select
Range("A1").Select
Next w
wn.Activate ' set current worksheet
' or sheets(1).activcat if want first sheet
End Sub

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Dickie Worton" wrote:

Hi,
Hope this is an easy one for someone.
As a novice with VBA I could do with some help in adding code to a worksheet
that will automatically move the active cell back to being cell A1 before I
close my worksheet.
Any suggestions?
Thanks,
Dickie

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
Move cursor to specific cell from a specific cell JSnow Excel Discussion (Misc queries) 4 August 29th 08 07:53 PM
Macro to Move Specific Data to Another Worksheet jeannie v Excel Worksheet Functions 1 January 20th 08 06:30 PM
Move Specific Data to Another Worksheet jeannie v Excel Worksheet Functions 3 January 19th 08 10:08 PM
Move Specific Text to new worksheet glensfallslady Excel Programming 3 October 31st 06 01:38 AM
Move curser to specific cell when closing Richard Excel Worksheet Functions 1 October 29th 06 12:49 PM


All times are GMT +1. The time now is 01:49 PM.

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

About Us

"It's about Microsoft Excel"