Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Locking cells with a checkbox using a macro.

Hello. I have an ongoing problem. I am trying to lock cells so they
cannot be changed as long as a checkbox on the active sheet is checked.
I have some code, but it runs an error and doesn't quite work anyway.
I have another macro that fills the boxes with values, but I want the
users to be able to adjust those values. Only after the checkbox is
checked, I want the access to those cells to be locked. Here is a
sampling of the code I have so far:

Sub chkLockAttribs_Click()
'
'Private Sub chkLockAttribs_Click()


Dim myRng As Range
Dim myPwd As String


myPwd = "secret"


Set myRng = ActiveSheet.Range("C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35")


ActiveSheet.Unprotect Password:=myPwd
myRng.Locked =
ActiveSheet.OLEObjects("chkLockAttribs").Object.Va lue
ActiveSheet.cmdRoll.Visible = Not
(ActiveSheet.chkLockAttribs.Value)
ActiveSheet.Protect Password:=myPwd



End Sub

The checkbox is chkLockAttribs and the button linked to a macro
generating values is cmdRoll. C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35 is the range of cells I want to lock after the checkbox is
checked. I don't really need a password protection on this. It's more
a convienence thing.

So any suggestions? Any and all help appreciated.

-SplatterKat-

aka -Robert Lizak-

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Locking cells with a checkbox using a macro.

I put a checkbox from the control toolbox toolbar on the worksheet. I named it
"chklockattribs".

I put a commandbutton from the control toolbox toolbar on that same worksheet.
I named it "cmdRoll".

I doubleclicked on that checkbox and pasted this into the code window that
opened:

Option Explicit
Private Sub chkLockAttribs_Click()

Dim myRng As Range
Dim myPwd As String

myPwd = "secret"

Set myRng = Me.Range("C18, D19:D23, D25, D26:F26, J19:J23,P33, P35")
Me.Unprotect Password:=myPwd
myRng.Locked = Me.chkLockAttribs.Value
Me.cmdRoll.Visible = Not (Me.chkLockAttribs.Value)
Me.Protect Password:=myPwd

End Sub


It worked fine for me.

If you used shapes from the Forms toolbar, make sure you include that info in
any followup.

SplatterKat wrote:

Hello. I have an ongoing problem. I am trying to lock cells so they
cannot be changed as long as a checkbox on the active sheet is checked.
I have some code, but it runs an error and doesn't quite work anyway.
I have another macro that fills the boxes with values, but I want the
users to be able to adjust those values. Only after the checkbox is
checked, I want the access to those cells to be locked. Here is a
sampling of the code I have so far:

Sub chkLockAttribs_Click()
'
'Private Sub chkLockAttribs_Click()

Dim myRng As Range
Dim myPwd As String

myPwd = "secret"

Set myRng = ActiveSheet.Range("C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35")

ActiveSheet.Unprotect Password:=myPwd
myRng.Locked =
ActiveSheet.OLEObjects("chkLockAttribs").Object.Va lue
ActiveSheet.cmdRoll.Visible = Not
(ActiveSheet.chkLockAttribs.Value)
ActiveSheet.Protect Password:=myPwd

End Sub

The checkbox is chkLockAttribs and the button linked to a macro
generating values is cmdRoll. C18, D19:D23, D25, D26:F26, J19:J23,
P33, P35 is the range of cells I want to lock after the checkbox is
checked. I don't really need a password protection on this. It's more
a convienence thing.

So any suggestions? Any and all help appreciated.

-SplatterKat-

aka -Robert Lizak-


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking everything except cells B4:B8 H New Users to Excel 2 July 6th 09 05:57 PM
Locking cells P. Zicari Excel Worksheet Functions 1 October 24th 07 11:42 PM
Locking Cells phil Excel Discussion (Misc queries) 1 December 6th 06 04:37 PM
locking formula in cells in without locking whole sheet SuziQ Excel Discussion (Misc queries) 1 July 21st 06 03:58 PM
Locking cells Chip Pearson Excel Programming 0 August 17th 03 10:21 PM


All times are GMT +1. The time now is 11:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"