Results 1 to 7 of 7

How to enable macros with protected worksheet

Threaded View

  1. #3
    Registered User
    Join Date
    07-25-2013
    Location
    Pathumtanee, Thailand
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: How to enable macros with protected worksheet

    Thank you for your suggestion Winon.
    I am very new to this. I wrote down this code that allows me to select multiple options from a drop down list.
    From the code that you gave me. I tried to add it at the beginning and at the end, but it kept saying error.
    If you don't mind helping me by showing where should I add your code in, I would be very much appreciated. Thanks again heaps
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngDV As Range
    Dim oldVal As String
    Dim newVal As String
    Dim lUsed As Long
    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 = 10 Or Target.Column = 11 Or Target.Column = 12 Or Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15 Or Target.Column = 16 Or Target.Column = 17 Or Target.Column = 18 Or Target.Column = 19 Or Target.Column = 20 Or Target.Column = 21 Or Target.Column = 22 Or Target.Column = 23 Or Target.Column = 24 Or Target.Column = 25 Or Target.Column = 26 Or Target.Column = 27 Or Target.Column = 28 Then
        If oldVal = "" Then
          'do nothing
          Else
          If newVal = "" Then
          'do nothing
          Else
            lUsed = InStr(1, oldVal, newVal)
            If lUsed > 0 Then
                If Right(oldVal, Len(newVal)) = newVal Then
                    Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
                Else
                    Target.Value = Replace(oldVal, newVal & ", ", "")
                End If
            Else
                Target.Value = oldVal _
                  & ", " & newVal
            End If
            
          End If
        End If
      End If
    End If
    
    exitHandler:
      Application.EnableEvents = True
    End Sub
    Last edited by Fotis1991; 09-13-2013 at 04:18 AM. Reason: added code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 08-06-2013, 08:21 AM
  2. A password protected Macro to enable and disable other macros?
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2011, 03:04 PM
  3. Enable Macros in Password-protected Excel File
    By Alleen86 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2011, 02:28 PM
  4. [SOLVED] How do I enable the spellchecker in a protected worksheet?
    By Anne CFS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2005, 04:05 PM
  5. Enable grouping in protected worksheet
    By malik641 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-06-2005, 07:34 AM

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