+ Reply to Thread
Results 1 to 8 of 8

Behavior of Locked Sheet Differs Based on How File is Opened

Hybrid View

  1. #1
    Registered User
    Join Date
    02-26-2024
    Location
    DK
    MS-Off Ver
    365
    Posts
    5

    Behavior of Locked Sheet Differs Based on How File is Opened

    I've created a macro that enables double-clicking on a cell to show only rows with matching information. This allows me to quickly filter a large table with numerous filters.

    The macro works as expected in the table, also after I've locked cells in other parts of the sheet.

    However, I've noticed it only works on cells containing a dropdown list until I close the file. After I reopen the file, it works on all cells except those containing a dropdown. I have to unlock and relock the sheet with the same permissions, to make the function working again in all cells (including those with dropdown lists).

    How can I ensure the file works properly upon opening, allowing me to use the double-click filter function in every cell, including those with dropdown lists?



    For information:
    I use this function to allow macros on the locked sheet
    Sub AllowMacroOnLockedSheet()
        Sheets("Sheet1").Protect Password:="Password", UserInterfaceOnly:=True
    End Sub
    My macro double-click filter-function
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    Dim ClickColum As Integer
    Dim ClickValue As String
    
    ClickColum= ActiveCell.Column
    ClickValue= ActiveCell.Value
    
    On Error Resume Next
    
        If Application.Intersect(ActiveCell, [Top]) Is Nothing Then
            If ActiveCell.Value <> "" Then
                ActiveSheet.Range("A:az").AutoFilter Field:=ClickColum, Criteria1:=ClickValue
            End If
        End If
    End Sub

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Hi there,

    You don't include your workbook, so it's difficult to make meaningful suggestions

    The first thing that occurs to me is that the routine "AllowMacroOnLockedSheet" should be called from a "Workbook_Open" routine - is this in fact the case?

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    02-26-2024
    Location
    DK
    MS-Off Ver
    365
    Posts
    5

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Hi Greg

    Yes, my workbook consist of this:
    Private Sub Workbook_Open()
        Call AllowMacroOnLockedSheet
    End Sub

  4. #4
    Registered User
    Join Date
    02-26-2024
    Location
    DK
    MS-Off Ver
    365
    Posts
    5

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Quote Originally Posted by Greg M View Post
    Hi there,

    You don't include your workbook, so it's difficult to make meaningful suggestions

    The first thing that occurs to me is that the routine "AllowMacroOnLockedSheet" should be called from a "Workbook_Open" routine - is this in fact the case?

    Regards,

    Greg M
    Hi Greg

    Can I offer additional information to you?

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,645

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Hi again,


    Can I offer additional information to you?

    You can indeed!

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    02-26-2024
    Location
    DK
    MS-Off Ver
    365
    Posts
    5

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Quote Originally Posted by Greg M View Post
    Hi again,



    You can indeed!

    Regards,

    Greg M
    Great! What information do you want? How can I best assist you?

    Workbook:
    Private Sub Workbook_Open()
        Call AllowMacroOnLockedSheet
    End Sub
    Module1
    Sub AllowMacroOnLockedSheet()
        Sheets("Sheet1").Protect Password:="Password", UserInterfaceOnly:=True
    End Sub
    Sheet1
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    
    Dim ClickColum As Integer
    Dim ClickValue As String
    
    ClickColum= ActiveCell.Column
    ClickValue= ActiveCell.Value
    
    On Error Resume Next
    
        If Application.Intersect(ActiveCell, [Top]) Is Nothing Then
            If ActiveCell.Value <> "" Then
                ActiveSheet.Range("A:az").AutoFilter Field:=ClickColum, Criteria1:=ClickValue
            End If
        End If
    End Sub
    How can I ensure the macro works properly upon opening, allowing me to use the double-click filter function in every cell, including those with dropdown lists?


    *edited to correct an error.
    Last edited by TroelsL; 03-11-2024 at 08:14 AM.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Is the AllowMacroOnLockedSheet routine really in Sheet1?
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Registered User
    Join Date
    02-26-2024
    Location
    DK
    MS-Off Ver
    365
    Posts
    5

    Re: Behavior of Locked Sheet Differs Based on How File is Opened

    Quote Originally Posted by rorya View Post
    Is the AllowMacroOnLockedSheet routine really in Sheet1?
    Sorry, no. The AllowMacroOnLockedSheet routine is defined is in "Module1".

    BeforeDoubleClick is in Sheet1

+ 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. Locked Excel Tab -> Unlocks if Opened in Google
    By mvyvoda in forum Excel General
    Replies: 0
    Last Post: 02-11-2021, 08:21 PM
  2. If The Sheet it A Newly Opened File does not exist
    By FLani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2015, 07:11 PM
  3. Automatically open a file in a specific file path when another sheet is opened
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2014, 11:05 AM
  4. Splash screen in file opened by VBA hinders further processing of opened file.
    By Rod38 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 09:53 AM
  5. Sheet A in file X to Sheet B in file Y when both files are opened by excel.
    By sunheroj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2012, 09:52 AM
  6. My excel file is locked for editing. How do I get it opened.
    By DaveyOLostWages in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-30-2006, 12:15 PM
  7. Excel file/Sheet Locked
    By Eileen in forum Excel General
    Replies: 1
    Last Post: 01-04-2005, 08:06 PM

Tags for this Thread

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