+ Reply to Thread
Results 1 to 2 of 2

Sheet-Password issues with macro

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Sheet-Password issues with macro

    Hello,

    My sheets are password protected, and I've set up the macros to automatically unlock (then lock) the sheets.
    However, I still get an protection-error when trying to run the macros (even though it unlocks the sheet first).

    I think this may be caused by Worksheet_Change, which also has password unprotect.
    So that the Worksheet_Change locks the sheet before the macro has run.

    Any suggestions as to how I can fix this? It worked before I made the Worksheet_Change unlock/lock sheets.

    Here is my Worksheet_Change code:

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ActiveSheet.Unprotect Password:="password"
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
        Cancel = True
    Call DrilldownMotBilde(True)
    End If
    ActiveSheet.Protect Password:="password"
    End Sub
    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        ActiveSheet.Unprotect Password:="password"
        Set MyPlage = Range("B4:B200")
        For Each Cell In MyPlage
          
            Select Case Cell.Value
              
             Case Is = "New"
                Cell.EntireRow.Interior.ColorIndex = 3
              
            Case Is = "In Progress"
               Cell.EntireRow.Interior.ColorIndex = 44
                      
            Case Is = "Waiting"
                Cell.EntireRow.Interior.ColorIndex = 34
                  
            Case Is = "Solved"
               Cell.EntireRow.Interior.ColorIndex = 50
            
            Case Is = "Aproval"
               Cell.EntireRow.Interior.ColorIndex = 17
                  
            Case Else
                Cell.EntireRow.Interior.ColorIndex = xlNone
              
            End Select
        Next
        
         If Target.Column <= Range("G:G").Column Then
        Application.EnableEvents = False
            If Range("A" & Target.Row).Value >= 1000000 And Range("A" & Target.Row).Value <= 39999999 Then
                 Range("H" & Target.Row).Value = Application.UserName
                 Range("I" & Target.Row).Value = Now
            End If
        Application.EnableEvents = True
    End If
    ActiveSheet.Protect Password:="password"
    End Sub

  2. #2
    Registered User
    Join Date
    06-26-2014
    Location
    Norway
    MS-Off Ver
    10
    Posts
    43

    Re: Sheet-Password issues with macro

    Found a solution myself! Disabled the worksheet_change during the macro:

    Application.EnableEvents = False
    'code
    Application.EnableEvents = True

+ 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. Recorded Macro and Sheet# naming issues
    By MsPenny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2014, 02:48 PM
  2. [SOLVED] Macro that pastes from one sheet to next available row in another sheet - range issues
    By njmiller31 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2012, 06:21 PM
  3. Macro Sheet & Formula Name Issues
    By ZHertz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-17-2011, 05:36 PM
  4. Replies: 1
    Last Post: 01-15-2009, 07:06 PM
  5. [SOLVED] password issues in Excel 2002
    By Stephen Larivee in forum Excel General
    Replies: 7
    Last Post: 02-18-2005, 07:06 PM

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