+ Reply to Thread
Results 1 to 11 of 11

select A1 on each sheet and activate sheet 1 when opening excel file

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    select A1 on each sheet and activate sheet 1 when opening excel file

    Hello,

    I would appreciate very much some help on setting up a VBA code that will simultaneously do the following:
    - activate sheet 1
    - select cell A1 in each of the sheets when they are activated (i.e. when I click on them)
    when I open my excel file that contains several sheets.

    Since I am not so familiar with programming, I googled a bit and found the following solutions for EACH of my requests:
    1. How to activate sheet 1:
    Private Sub Workbook_Open()
    Sheet1.Range("A1").Select
    End Sub
    2. How to select A1 in each of the sheets when they are activated:
    For Each WSheet In Worksheets
    WSheet.Activate
    Range("A1").Select
    Next
    End Sub

    My concern is now how to combine these two codes into one.

    Looking forward to receiving an efficient solution.


    Brgs
    Amy

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    Maybe:

    Please Login or Register  to view this content.
    And

    Please Login or Register  to view this content.
    I may be wrong but I think the second code is default anyway.

  3. #3
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    Thanks for the quick answer. Unfortunately, the code 2 does not work. It doesn't activate cell A1.

    Any other suggestions?

    Please keep in mind that I would like ONE code that will perform both actions. I already tried with the codes that I mentioned in my 1st post, one below the other. But as soon as I add the 2nd one, the 1st one is "excluded" and won't perform it's "duty" any more.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    Both should work. They go in the Thisworkbook module. Seems you already know this from your first post. In that module is a Sheet Activate Event on the right hand side drop down. Place the 2nd code there. I tested it before providing it.

  5. #5
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    I attachd a screen shot of how I did it. Please have a look... (I placed the code in the yellow-highlighted "ThisWorkbook").
    It still won't work.
    Attached Images Attached Images

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    It's in the right place. It works for me. Does this work for you??
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    me again.

    I got an answer! This is the code that worked good for my file:
    Private Sub workbook_Open()

    Dim x As Long

    Application.ScreenUpdating = False

    For x = Worksheets.Count To 1 Step -1
    With Worksheets(x)
    If .Visible = True Then
    Application.Goto .Range("A1"), True
    End If
    End With
    Next x

    Sheets(1).Select

    Application.ScreenUpdating = True

    End Sub


    I am still wondering why none of the other codes worked for me, while for the others did. Does my excell have a bug or just an "unexperienced user"???!

    I appreciate all of your effort!!! Thanks a lot.

  8. #8
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    No, it doesn't work. Weird. (??) Here is what is shows...
    Attached Images Attached Images

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    This should definitly work

    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    Did you download the attachment provided? Did you test it?

  11. #11
    Registered User
    Join Date
    04-12-2012
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: select A1 on each sheet and activate sheet 1 when opening excel file

    @ JOHN H. DAVIS: yes, I tested it. But it didn't work. I proivded a screen shot on my last post (@ 1:53 PM).

    @ bakerman2: Your code works, as well! Thnx for showing another apprach.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel Macro - Filter button activate on both sheet if activated on one sheet
    By umeshbanga in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2014, 02:22 PM
  2. Replies: 2
    Last Post: 05-31-2014, 02:05 AM
  3. Activate a specific sheet when opening a workbook.
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-19-2013, 10:38 AM
  4. [SOLVED] Activate a nominated sheet when opening a workbook
    By Aland2929 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-10-2013, 03:00 AM
  5. Activate VB Macro when opening excel file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-21-2012, 01:35 PM
  6. Delete Excel sheet without opening file
    By ena_george in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2009, 07:24 PM
  7. Select a sheet and activate a Window
    By Hari Prasadh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-31-2005, 06:06 AM

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