Solved

VBA unlock and lock cell

Posted on 2013-12-11
7
517 Views
Last Modified: 2013-12-11
Folks,
I have a need to unlock a range (B3:C3), clear the cells and then lock them. What I've tried below fails so a little tweaking here is appreciate:

DetermineLastUseCell.Range("B3:C3").Locked = False
Worksheets("DetermineLastUseCell").Range("B3:C3").Clear
Worksheets("DetermineLastUseCell").Range("B3:C3").Locked = True

Open in new window


Thanks
0
Comment
Question by:Frank Freese
  • 3
  • 2
  • 2
7 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39711258
If the sheet is protected you need to unprotect it first, then you can just clear the cells and reprotect the sheet. (no need to change the Locked property of the cells).
0
 

Author Comment

by:Frank Freese
ID: 39711273
I forgot to metion tha tthe sheet is protected:
ActiveSheet.Unprotect Password = "123memphis"
Range("B3:C3").Select
Selection.Locked = False
Worksheets("DetermineLastUseCell").Range("B3:C3").Clear
Range("B3:C3").Select
Selection.Locked = True
ActiveSheet.Protect Password = "123memphis"

Open in new window

Still can't get by the first line of code
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 39711285
You forgot the colons:

ActiveSheet.Unprotect Password:="123memphis"
Range("B3:C3").Clear
ActiveSheet.Protect Password:="123memphis"

Open in new window


Otherwise you are passing an expression rather than a named argument.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Frank Freese
ID: 39711303
Folks,
I've changed my code to this. My objective is unportect the worksheet from B3:C3, clear B3:C3, redraw the cell B3 then protect the worksheet again.
ActiveSheet.Unprotect Password = "123memphis"
Range("B3:C3").Select
Worksheets("DetermineLastUseCell").Range("B3:C3").Clear
Dim rng As Range
   Set rng = Range("B3")
    With rng.Borders
        .LineStyle = xlContinuous
        .Color = vbBlack
        .Weight = xlThin
    End With
ActiveSheet.Protect Password = "123memphis"

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39711322
If you are only wanting to clear the contents of the cell use:

Range("B3:C3").ClearContents

You won't then have to redo the borders on B3.

Thanks
Rob H
0
 

Author Closing Comment

by:Frank Freese
ID: 39711324
thanjs - I failed to see that I did not include the :
Apprciate it - on to next problem
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39711344
So you would end up with

ActiveSheet.Unprotect Password:="123memphis"
Range("B3:C3").ClearContents
ActiveSheet.Protect Password:="123memphis"

Open in new window


The colons that rorya was referring to were after the word Password.

Thanks
Rob H
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question