+ Reply to Thread
Results 1 to 9 of 9

Clearing Filters and Returning to Cell A1

  1. #1
    Registered User
    Join Date
    07-28-2008
    Location
    Moncton
    MS-Off Ver
    2003
    Posts
    53

    Clearing Filters and Returning to Cell A1

    I am not sure if this is doable in VB or if there is an excel function to do this but I am using a rather large worksheet that is shared amongst my staff. I would like to have the sheet clear any filters that have been used by one member and for the sheet to save with the cursor in the home cell (A1). This way the sheet is ready for the next user. Can this be done with VB?

    I have never used VB before in Excel. New territory for me so any hand-holding explanations would be greatly appreciated.
    Last edited by DentonHTHS; 03-02-2009 at 06:22 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Clearing Filters and Returning to Cell A1

    Try this event macro.

    Code goes in ThisWorkbook module. Save the code. Open file and user will need to enable macros

    http://www.contextures.com/xlvba01.html#Workbook

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    07-28-2008
    Location
    Moncton
    MS-Off Ver
    2003
    Posts
    53

    Re: Clearing Filters and Returning to Cell A1

    Thanks for the code, VBA Noob. I think I inserted correctly but I am still having problems which may have been due to my explanation and not your code. When I save the file and reopen it, my filters disappear (which I suppose is a clear). What I meant is that I wanted the filters to reset so that the next person could filter based on their needs. Sometimes my less than knowledgeable staff get confused when the workbook opens up and its not back at cell A1 and there are several filters that have been left behind when the file was saved by the previous user.

    So, I would like the filters to stay but that they would be reset to not presently filtering data when the workbook is open. I'd also like the workbook to always have the cursor in cell A1 when it opens. I couldn't seem to get this code to do that.

    Thanks for all the help!

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Clearing Filters and Returning to Cell A1

    Replace this line
    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    See link for more
    http://www.contextures.com/xlautofilter03.html#All

    VBA Noob

  5. #5
    Registered User
    Join Date
    07-28-2008
    Location
    Moncton
    MS-Off Ver
    2003
    Posts
    53

    Re: Clearing Filters and Returning to Cell A1

    Thanks, VBANoob. The filter resetting is now working when I close and reopen the file but it doesn't seem to be putting the cursor at the home cell. I wonder if I am doing some thing wrong? This is how I pasted the code into my workbook.

    Please Login or Register  to view this content.
    Last edited by DentonHTHS; 03-02-2009 at 11:49 AM.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Clearing Filters and Returning to Cell A1

    Works for me.

    See attached

    You could try a sheet activate macro also in ThisWorkbook so when a user selects a sheet it automatically goes to A1

    Please Login or Register  to view this content.
    VBA Noob
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-28-2008
    Location
    Moncton
    MS-Off Ver
    2003
    Posts
    53

    Re: Clearing Filters and Returning to Cell A1

    Would saving the workbook change the behaviour of the code? Some of my users save the file before closing (even though they don't have to). If the same user then reopened the book would it open in the position it was saved or would the code override that?

    I think I will put this new code in that you suggested. Should it go before or after the previous code or does it matter? Thanks for your patience with the noobie.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Clearing Filters and Returning to Cell A1

    Would saving the workbook change the behaviour of the code?
    No as only runs when workbook is open (2nd code when a sheet is selected)

    If the same user then reopened the book would it open in the position it was saved or would the code override that?
    Code should override it. It loops from the last sheet to the first unselect the filter and should select cell A1 for that workbook...Does for me

    Should it go before or after the previous code or does it matter?
    Doesn't matter as long as it's in ThisWorkbook module.
    Only problem is it won't work for the activesheet only when they select the first sheet

    VBA Noob

  9. #9
    Registered User
    Join Date
    07-28-2008
    Location
    Moncton
    MS-Off Ver
    2003
    Posts
    53

    Re: Clearing Filters and Returning to Cell A1

    I saved the file you attached after scrolling down to row 90 or so. When I reopened the file it opened up at that position. As soon as I hit a direction key it did go up to the top of the sheet. Not sure why I am getting this behaviour. Still if a keystroke will get the sheet to return to the top that will help a lot with people getting lost in rows and columns.

    Thanks very much for your help!

+ 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