+ Reply to Thread
Results 1 to 5 of 5

Thread: Showing All Data in a Protected Worksheet

  1. #1
    Registered User
    Join Date
    09-29-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Showing All Data in a Protected Worksheet

    Hi All,

    I have a worksheet with filtering options. I would like to have the filters be reset, or to show all data, when the worksheet is closed that way each time it is opened it will not have a filter set up. However, this spreadsheet is also a protected one. I know that the ShowAllData in VBA cannot be used on a protected sheet. Therefore I need assistance with the following:

    I need to write a VBA code that will unprotect, show all data, and then protect the worksheet all when the workbook is being closed.

    Any suggestions?

    Thanks!!

  2. #2
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Showing All Data in a Protected Worksheet

    Perhaps something like this
    Option Explicit
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        With Sheet1
            .Unprotect
            If .AutoFilterMode Then
                .ShowAllData
            End If
            .Protect
        End With
    End Sub
    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    09-29-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Showing All Data in a Protected Worksheet

    That will work great except for that now it prompts me to enter my password. How can I setup the password in the VBA code so that I don't have to enter it each time it protects and unprotects the spreadsheet? Thanks!!!

  4. #4
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Showing All Data in a Protected Worksheet

    Perhaps this
    Option Explicit
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        With Sheet1
            .Unprotect Password:="Secret"
            If .AutoFilterMode Then
                .ShowAllData
            End If
            .Protect Password:="Secret"
        End With
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    09-29-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Showing All Data in a Protected Worksheet

    Thank you for all of the help. Unfortunately I have run into a bigger issue I did not forsee previously. I am going to be sharing this workbook and therefore the spreadsheet cannot protect and unprotect in a shared workbook.

    Anyone have any suggestions of another way to accomplish the show all data?

    Thanks!

+ 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.2.0