+ Reply to Thread
Results 1 to 6 of 6

Way to Get Around Macros Not Working in Protected Sheet?

  1. #1
    Registered User
    Join Date
    05-16-2013
    Location
    Chiang Mai, Thailand
    MS-Off Ver
    Excel 2010
    Posts
    34

    Way to Get Around Macros Not Working in Protected Sheet?

    Hi,

    Is there a way to get around macros not working in a protected sheet? I want to allow user to enter multiple responses using the following code, but it won't work if sheet is protected.

    Please Login or Register  to view this content.
    Is there a code I can use to override the disabling of macro when I protect sheet? I want to protect sheet so users don't accidentally change codes, field titles, lists, etc....

    Thanks,
    Lyndy


    Moderators note: code tags added for you - this time
    Last edited by FDibbins; 05-21-2013 at 11:55 PM. Reason: Added code tags

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Way to Get Around Macros Not Working in Protected Sheet?

    Hi, lyndy256,

    you may pass the parameter UserInterfaceOnly:=True when protecting your sheet which would enable macros to run but keep users dfrom editing (please mind this is a volatile settiung and wonīt get stored with the workbook so the action should be called either in the Workbook_Open-event or when activating the sheet):

    Please Login or Register  to view this content.
    Using this will keep the sheet protection even if due to run time error the code may fail while with unprotecting the sheet at the start it will be fully accessible unless an error handler leads the code to protect the sheet on error or at the end of the procedure.

    HTH,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-16-2013
    Location
    Chiang Mai, Thailand
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Way to Get Around Macros Not Working in Protected Sheet?

    Hi Holger,

    Thanks for your reply.

    Sorry if my follow up question is dumb: where exactly do I insert the code you provided-above or below my current code or in a separate macro? My code is below:
    Please Login or Register  to view this content.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    If Target.Count > 1 Then GoTo exitHandler

    On Error Resume Next
    Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
    On Error GoTo exitHandler

    If rngDV Is Nothing Then GoTo exitHandler

    If Intersect(Target, rngDV) Is Nothing Then
    'do nothing
    Else
    Application.EnableEvents = False
    newVal = Target.Value
    Application.Undo
    oldVal = Target.Value
    Target.Value = newVal
    If Target.Column = 11 Or Target.Column = 23 Then
    If oldVal = "" Then
    'do nothing
    Else
    If newVal = "" Then
    'do nothing
    Else
    Target.Value = oldVal & ", " & newVal
    End If
    End If
    End If
    End If

    exitHandler:
    Application.EnableEvents = True

    End Sub

    Please Login or Register  to view this content.
    Lyndy

  4. #4
    Registered User
    Join Date
    05-16-2013
    Location
    Chiang Mai, Thailand
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Way to Get Around Macros Not Working in Protected Sheet?

    BTW, I am hitting # sign as Forum Rules indicate but it's not showing code as example does.

    The instructions say, " Select your code and click the # button at the top of the post window...."

    I copy my code from my Excel Worksheet and insert into my message body. Then hit #. I'm not sure what I am doing wrong, but maybe someone can clarify what is meant by "select code."

    Thanks,
    Lyndy

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Way to Get Around Macros Not Working in Protected Sheet?

    Hi, lyndy256,

    the code you posted needs the event to be triggered so any action regarding protecting the worksheet needs to be done prior to that. Thatīs why I mentioned the Workbook_Open event in ThisWorkook where the protection with UserInterfaceOnly:=True may take place and thus allow your macro to run.

    Code in ThisWorkbbok:
    Please Login or Register  to view this content.
    Code behind "Tabelle1"
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-16-2013
    Location
    Chiang Mai, Thailand
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Way to Get Around Macros Not Working in Protected Sheet?

    Got it!

    Thanks for your patience. I am new to coding and I do better with more explicit instructions, though I appreciate if I want to learn coding I need to learn the language of coding.

    I see from looking at the attachment you sent through that the answer to my question is that the macro that allows the code to work even if worksheet is protected must be kept separately and before the main macro that allows multiple entries in one cell. This is how I understand it. "The Workbook_Open event in ThisWorkook where the protection with UserInterfaceOnly:=True may take place and thus allow your macro to run" doesn't make much sense to me.

    Cheers,
    Lyndy

+ 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