Macro for blocker from using cell range
See responses in-line
On Tue, 23 Mar 2010 10:50:06 -0700, Lenny
wrote:
"Lenny" replied: Gord, my thanks for the reply and assistance. Would it be
an imposition to ask further if you might explain in 'lay' terms what each
line or block of of the code is doing. I know lots of site visitors are
trolling for the code, but I would like to understand what the code is
telling me (this from a newbie). Further explanation would be greatly
appreciated and anyone new to programming might also get a learning
experience. Regards - Lenny
"Gord Dibben" wrote:
With "qwerty" as defined name for range =Sheet1!$A$1:$F$12,Day!$A$26:$F$34
select those cells using CTRL + click then InsertNameDefine
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Selection is whatever cell you click on
Dim myrange As Range
see Dim in VBA help
Set myrange = Me.Range("qwerty")
"qwerty" is a defined range
me is parent object......in this case the worksheet
On Error GoTo ws_exit:
if an error is encountered go to ws_exit which resets enableevents to true
Application.EnableEvents = False
prevent looping
If Not Intersect(Target, myrange) Is Nothing Then
if target(selected cell) is within "myrange" move on next step
With Me
protect the sheet
.Protect Password:="justme"
.EnableSelection = xlNoRestrictions
allow selection of any cell
End With
Else
If Intersect(Target, myrange) Is Nothing Then
if target is not within "myrange" then unprotect the sheet
Me.Unprotect Password:="justme"
End If
End If
ws_exit:
Application.EnableEvents = True
re-enable events
End Sub
Paste into Sheet1 code module.
Gord Dibben MS Excel MVP
If you look at the second set of code I posted you will see the difference.
No named range.........just locked or unlocked cells chosen by yourself
prior to running the code.
Gord
On Tue, 23 Mar 2010 09:10:16 -0700, Lenny
wrote:
Is there a way to write code that can unlock a worksheet (w/password)
allowing the user access to functionality while relocking (w/password) the
worksheet should the user mouse click or move into a range of cells that
would normally be locked?
Assistance and a learning opportunity is always appreciated...
Regards, Lenny
.
|