Results 1 to 6 of 6

Error message when the work sheet is protected with password

Threaded View

  1. #1
    Registered User
    Join Date
    10-19-2012
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    46

    Error message when the work sheet is protected with password

    Hello Forum,
    I have a workbook with 2 VBA codes. The workbook and the codes work fine until I protect the sheet with password. It stills give me the correct result but as the same time it gives the error:

    Run-time error '1004:
    Application-defined or object-defined error

    How can I remove this error message when the work sheet is protected with password?
    Thank you so much for your help
    Thup_98


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim sPrompt As String, iReply As Integer, i As Integer
    
    If Intersect(Target, Me.Range("A2:A9")) Is Nothing Or Target.Count > 1 Then
         Exit Sub
         End If
    
    If Target.Row = 9 Then
              sPrompt = "Are you sure you want to reset all data validations?"
              iReply = MsgBox(sPrompt, vbYesNo)
             If iReply = 6 Then Me.Range("C2:C8,F2:F8,I2:I8,N2:N8") = "NA"
             If iReply = 6 Then Me.Range("D2:D8,G2:G8,J2:J8,O2:O8") = 0
         Else
              i = Target.Row
              sPrompt = "Are you sure you want to reset all data validations in row " & i & "?"
              iReply = MsgBox(sPrompt, vbYesNo)
             If iReply = 6 Then Me.Range("C" & i & ",F" & i & ",I" & i & ",N" & i) = "NA"
             If iReply = 6 Then Me.Range("D" & i & ",G" & i & ",J" & i & ",O" & i) = 0
         End If
    End Sub



    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
        Dim part As String
        If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
        
        
         With Target
         If .Column = 3 Or .Column = 6 Or .Column = 9 Or .Column = 14 Then
    If .Value = "NA" Then .Offset(0, 1).Value = 0
    End If
         End With
    If Target.Column = 14 And Target.Value = "_9000_0001CT" Then
            Target.Offset(0, 1).Value = 1
        End If
        If Target.Column = 14 And Target.Value = "_9000_0001" Then
            Target.Offset(0, 1).Value = 1
        End If
        If Target.Column = 14 And Target.Value = "_9000_0008_220V" Then
            Target.Offset(0, 1).Value = 1
        End If
        If Target.Column = 14 And Target.Value = "_9000_0001CT" Then
            Target.Offset(0, 1).Value = 1
        End If
        If Target.Column = 14 And Target.Value = "_9000_0002" Then
            Target.Offset(0, 1).Value = 1
        End If
        If Target.Column = 4 And Target.Offset(0, -1).Value <> "NA" Then
            part = Target.Offset(0, -1).Value
            Target.Offset(0, -1).Value = Right(Replace(part, "_", "-"), Len(part) - 1)
        End If
        If Target.Column = 7 And Target.Offset(0, -1).Value <> "NA" Then
            part = Target.Offset(0, -1).Value
            Target.Offset(0, -1).Value = Right(Replace(part, "_", "-"), Len(part) - 1)
        End If
        If Target.Column = 10 And Target.Offset(0, -1).Value <> "NA" Then
            part = Target.Offset(0, -1).Value
            Target.Offset(0, -1).Value = Right(Replace(part, "_", "-"), Len(part) - 1)
        End If
           If Target.Column = 15 And Target.Offset(0, -1).Value <> "NA" Then
            part = Target.Offset(0, -1).Value
            Target.Offset(0, -1).Value = Right(Replace(part, "_", "-"), Len(part) - 1)
        End If
        End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 01-29-2016, 03:57 PM
  2. password protected hide sheet not work properle
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-30-2013, 09:40 AM
  3. Macros stop to work when work sheet is protected. Run time error 1004
    By sellim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 01:14 AM
  4. Error Handler for Incorrect Password (Protected Sheet)
    By jasoncw in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-01-2007, 06:44 PM
  5. PLEASE HELP! Copy sheet with password protected cells debug error
    By bsnapool in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2006, 07:04 AM
  6. [SOLVED] Error message with protected sheet
    By HRman in forum Excel General
    Replies: 1
    Last Post: 11-28-2005, 03:10 PM
  7. Custom Error Message for Protected sheet
    By hailnorm in forum Excel General
    Replies: 1
    Last Post: 01-25-2005, 03:03 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