+ Reply to Thread
Results 1 to 6 of 6

Unlocking Range in a protected Sheet - VBA

  1. #1
    Registered User
    Join Date
    08-01-2015
    Location
    Kuwait
    MS-Off Ver
    2013
    Posts
    4

    Question Unlocking Range in a protected Sheet - VBA

    Hey,
    I've been trying to unlock a specific range in a protected sheet after performing the below steps, but it doesn't seem to be working.
    What I am actually trying to do here is to unlock a specific range ( =$X$3:$Y$5000,$AA$3:$AD$5000,$AN$3:$AO$5000,$G$3:$V$5000,$A$3:$D$5000 ; (Namely: "Merch") ).
    But the codes I tried with just unlock a cell, and it gets permanently unlocked, and the other cells under "Merch" remain locked.
    Is there anyway to unlock this range?


    Note: Sheet is protected, and the range "Merch" is unlocked by the users before the below code gets triggered.

    Thanks in Advance!



    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Unlocking Range in a protected Sheet - VBA

    Hi
    you state that the range is named Merch. The following two routines unlock and lock the named range. I am sure you will be able to incorporate them into your solution.

    Please Login or Register  to view this content.


    click on the * Add Reputation if this was useful or entertaining.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,051

    Re: Unlocking Range in a protected Sheet - VBA

    If the sheet is protected, do you have the password, or is this some1 elses file you are working on?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    08-01-2015
    Location
    Kuwait
    MS-Off Ver
    2013
    Posts
    4

    Re: Unlocking Range in a protected Sheet - VBA

    Hello Tony,
    Thank you so much for your response.

    This is what I got..



    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myRange As String
    Dim myFoundRange As String
    Dim wks As Worksheet
    Dim rng As Range

    If Target.Column = 1 And Target.Count = 1 Then
    If Len(Target.Value) > 0 Then
    Worksheets("MASTERFILE").Unprotect Password:="ssmaster16"
    Application.EnableEvents = False
    myRange = Target.Address
    On Error GoTo exit_sub
    Range(Cells(1, "A"), Cells(Target.Row - 1, "A")).Find(What:=Target.Value, After:=Range("A1"), LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    On Error GoTo 0
    myFoundRange = ActiveCell.Address
    Range(myFoundRange).Resize(, 16).Copy
    Range(myRange).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Set wks = ActiveSheet
    Set rng = wks.Range("merch")
    rng.Locked = False
    ActiveSheet.Protect Password:="ssmaster16"


    End If
    End If
    exit_sub:
    Err.Clear
    Application.EnableEvents = True


    End Sub



    Now I am getting RUN TIME ERROR'1004': " Method "Range of objects" _ "Worksheet" Failed "


    Feel free to laugh at me


  5. #5
    Registered User
    Join Date
    08-01-2015
    Location
    Kuwait
    MS-Off Ver
    2013
    Posts
    4

    Question Re: Unlocking Range in a protected Sheet - VBA

    Hey Ford,
    yes I do have the main password and the passwords of the ranges.
    Any idea?

    Thanks!
    Last edited by sahal; 12-14-2015 at 02:34 AM.

  6. #6
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Unlocking Range in a protected Sheet - VBA

    Ok,
    First :use code tags

    Now I am puzzled - the way I am reading it (and I may be reading it wrong) ...
    This is kicked off by the worksheet_change event which is activated by a change to the cell value. For this to happen the cell must already be unlocked. Also the update is just to the Target cell (which being the changed cell) must by definition be unlocked.

    So there should be no need to unlock the sheet.

    You also have rather a muddle of addressing the target. So what do you think the routine is trying to do?

    PS if I have got it wrong and you are updating a locked cell you will get an error on the end sub

+ 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. Unlocking password protected VBA project
    By samrohn77 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-29-2015, 07:37 AM
  2. Unlocking Chart Axis Title under locked sheet without unlocking the sheet
    By dalelengle in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2012, 08:59 PM
  3. unlocking some cells on a protected sheet
    By Frank49 in forum Excel General
    Replies: 1
    Last Post: 07-24-2012, 07:08 PM
  4. Locking/Unlocking Cells in Protected Worksheets
    By dteresinski in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-16-2010, 08:26 AM
  5. Unlocking Macro in protected sheet
    By mag7417 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-28-2005, 09:04 AM
  6. [SOLVED] Unlocking pwd protected vba modules
    By Dan Thompson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2005, 08:05 PM
  7. Unlocking Cells when a worksheet is protected...
    By racmb1975 in forum Excel General
    Replies: 2
    Last Post: 05-03-2005, 04: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