Consulting

Results 1 to 3 of 3

Thread: Solved: Unprotect Work sheet to allow Macro to run

  1. #1
    VBAX Contributor
    Joined
    Dec 2006
    Posts
    193
    Location

    Solved: Unprotect Work sheet to allow Macro to run

    I thought I knew this one but apparently not .If the work sheet "TS SP" refered to in the code below is protected, where would I need to insert the code "Work Sheet unprotect" are some other code to unprotect the work sheet "TS SP"

    THANKS


    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "B:B" '<== change to suit
    Dim RowNum As Long

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target

    RowNum = Application.Match(.Value, Worksheets("TS sp").Columns(1), 0)
    Worksheets("TS sp").Rows(RowNum).SpecialCells(xlCellTypeConstants).ClearContents
    Worksheets("TS SP").Rows(RowNum).Cut
    Worksheets("TS SP").Rows(38).Insert Shift:=xlDown
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/VBA]

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Try the following code

    [vba]
    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "B:B" '<== change to suit
    Dim RowNum As Long

    On Error GoTo ws_exit
    Application.EnableEvents = False
    Sheets("TS SP").UnProtect password:="password"
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    With Target

    RowNum = Application.Match(.Value, Worksheets("TS sp").Columns(1), 0)
    Worksheets("TS sp").Rows(RowNum).SpecialCells(xlCellTypeConstants).ClearContents
    Worksheets("TS SP").Rows(RowNum).Cut
    Worksheets("TS SP").Rows(38).Insert Shift:=xlDown
    End With
    End If

    ws_exit:
    Sheets("TS SP").Protect password:="password"
    Application.EnableEvents = True
    End Sub
    [/vba]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Regular HaHoBe's Avatar
    Joined
    Aug 2004
    Location
    Hamburg
    Posts
    89
    Location
    Hi, BENSON,

    why not set the protection with UserInterfaceOnly:=True on opening or activating the sheet to allow any macro code to be executed?

    Ciao,
    Holger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •