Return All Sheets to Cell A1 before save

  • Follow


Hi

I have a workbook which comprises 11 worksheets. Before saving the workbook, 
I would like to return all sheets to cell A1 except for two worksheets - one 
called "Database-address" and the other "Database - Name" which asre to be 
returned to cells A4 and A6 respectively.

How can I do this with vba code.

Thanks

Darryl


0
Reply Darryl 11/30/2009 10:09:49 PM

Darryl
    Place this macro in the ThisWorkbook module.  Note that you have to have 
2 sheets named exactly as they are named in this macro, spaces and all.  HTH 
Otto

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As 
Boolean)
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Select
        If ws.Name <> "Database-address" And ws.Name <> "Database - Name" 
Then
            Range("A1").Select
        Else
            If ws.Name = "Database-address" Then Range("A4").Select
            If ws.Name = "Database - Name" Then Range("A6").Select
        End If
    Next ws
End Sub

"Darryl" <darryl4452@internode.on.net> wrote in message 
news:009dc736$0$26854$c3e8da3@news.astraweb.com...
> Hi
>
> I have a workbook which comprises 11 worksheets. Before saving the 
> workbook, I would like to return all sheets to cell A1 except for two 
> worksheets - one called "Database-address" and the other "Database - Name" 
> which asre to be returned to cells A4 and A6 respectively.
>
> How can I do this with vba code.
>
> Thanks
>
> Darryl
>
> 
0
Reply Otto 11/30/2009 11:35:30 PM


Put this in the ThisWorkbook module and change sheet names and range to 
suit.

Private Sub Workbook_BeforeSave _
(ByVal SaveAsUI As Boolean, Cancel As Boolean)
sheets.Select
Range("a1").Select
Application.Goto sheets("sheet2").Range("a6")
Application.Goto sheets("sheet3").Range("a8")
End Sub

-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com
"Darryl" <darryl4452@internode.on.net> wrote in message 
news:009dc736$0$26854$c3e8da3@news.astraweb.com...
> Hi
>
> I have a workbook which comprises 11 worksheets. Before saving the 
> workbook, I would like to return all sheets to cell A1 except for two 
> worksheets - one called "Database-address" and the other "Database - Name" 
> which asre to be returned to cells A4 and A6 respectively.
>
> How can I do this with vba code.
>
> Thanks
>
> Darryl
>
> 

0
Reply Don 11/30/2009 11:39:11 PM

2 Replies
440 Views

(page loaded in 0.77 seconds)

Similiar Articles:
















7/25/2012 5:49:09 PM


Reply: