+ Reply to Thread
Results 1 to 2 of 2

Range all sheets to cell "A1" before closing file

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Range all sheets to cell "A1" before closing file

    Friends,

    Before closing the file, I want Excel to automatically organize sheets, putting the cursor in cell "A1" of each of them and activating the first sheet, then I want it to save the workbook.

    To do this, I use the code below...

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        
        Sheets("Sheet5").Select
        Range("A1").Select
    
        Sheets("Sheet4").Select
        Range("A1").Select
    
        Sheets("Sheet3").Select
        Range("A1").Select
    
        Sheets("Sheet2").Select
        Range("A1").Select
    
        Sheets("Sheet1").Select
        Range("A1").Select
    
        ThisWorkbook.Save
    
    End Sub
    Is there any other "easier" way to do this?

    Thanks for your attention, guys.

    Hugs.

    Bruno

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Bruno,

    This should work for you:
    Dim x As Long
    For x = ThisWorkbook.Sheets.Count To 1 Step -1
        Sheets(x).Activate
        Cells(1, 1).Select
    Next x
    ThisWorkbook.Save
    Hope this helps,
    theDude

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1