Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA unlock and lock cell

Posted on 2013-12-11
7
Medium Priority
?
538 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 34

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 34

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

810 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