PC Review


Reply
Thread Tools Rate Thread

Cursor and Sheet Protection may09

 
 
Neal Zimm
Guest
Posts: n/a
 
      27th May 2009

Hi All,
I use the procs below to protect and unprotect sheets.

At times, (and I can't find the 'pattern'), I lose the
cursor after protecting the sheet.

After 'manual' protection the cursor moves to a unlocked cell.

If I've changed a locked cell in a macro, do I have to select a
Not .Locked cell to make sure the cursor is there
after protection ?

Thanks.



Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
If Not Ws Is Nothing Then Ws.UNprotect Id
End Sub

' Code to change a range

Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
Optional SelectionType As Long = xlUnlockedCells)

If Not Ws Is Nothing Then
Ws.Protect Id, AllowFormattingCells:=True
Ws.EnableSelection = SelectionType
End If
End Sub
--
Neal Z

 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      27th May 2009
You can find unlocked cells like this

Dim r as Excel.Range

for each r in WS.UsedRange
if not r.locked then
'Unlocked
else
'Locked
end if
next r


"Neal Zimm" wrote:

>
> Hi All,
> I use the procs below to protect and unprotect sheets.
>
> At times, (and I can't find the 'pattern'), I lose the
> cursor after protecting the sheet.
>
> After 'manual' protection the cursor moves to a unlocked cell.
>
> If I've changed a locked cell in a macro, do I have to select a
> Not .Locked cell to make sure the cursor is there
> after protection ?
>
> Thanks.
>
>
>
> Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
> If Not Ws Is Nothing Then Ws.UNprotect Id
> End Sub
>
> ' Code to change a range
>
> Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
> Optional SelectionType As Long = xlUnlockedCells)
>
> If Not Ws Is Nothing Then
> Ws.Protect Id, AllowFormattingCells:=True
> Ws.EnableSelection = SelectionType
> End If
> End Sub
> --
> Neal Z
>

 
Reply With Quote
 
Neal Zimm
Guest
Posts: n/a
 
      27th May 2009
Wow Barb, that was fast ....

I guess I was not clear in my question, I know about the .locked property
and how to find cells that are/not locked.

To restate, when I manually protect a sheet, the cursor always moves to a
not locked cell if there is one.

In my VBA code however, there are times when I unprotect a sheet to make
changes to locked cells, then, after protecting the sheet, when I go back to
look at it, there is NO cursor to be found. When I unprotect the sheet
and then re-protect it, the cursor magically comes back to life.

How do I stop this from happening ? I am hoping that your answer meant
that I do indeed have to find a unlocked cell before protecting the sheet.

But if that's true, that why does that never happen manually ?

Thanks,
Neal



--
Neal Z


"Barb Reinhardt" wrote:

> You can find unlocked cells like this
>
> Dim r as Excel.Range
>
> for each r in WS.UsedRange
> if not r.locked then
> 'Unlocked
> else
> 'Locked
> end if
> next r
>
>
> "Neal Zimm" wrote:
>
> >
> > Hi All,
> > I use the procs below to protect and unprotect sheets.
> >
> > At times, (and I can't find the 'pattern'), I lose the
> > cursor after protecting the sheet.
> >
> > After 'manual' protection the cursor moves to a unlocked cell.
> >
> > If I've changed a locked cell in a macro, do I have to select a
> > Not .Locked cell to make sure the cursor is there
> > after protection ?
> >
> > Thanks.
> >
> >
> >
> > Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
> > If Not Ws Is Nothing Then Ws.UNprotect Id
> > End Sub
> >
> > ' Code to change a range
> >
> > Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
> > Optional SelectionType As Long = xlUnlockedCells)
> >
> > If Not Ws Is Nothing Then
> > Ws.Protect Id, AllowFormattingCells:=True
> > Ws.EnableSelection = SelectionType
> > End If
> > End Sub
> > --
> > Neal Z
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Protection Best Practice: AKA: Real Sheet Protection Mushman(Woof!) Microsoft Excel Misc 4 30th Dec 2009 01:20 AM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Microsoft Excel Setup 0 29th Dec 2009 06:50 AM
move cursor on one sheet moves cursor on all sheets =?Utf-8?B?dGR3b3JkZW4=?= Microsoft Excel Misc 2 22nd Jul 2007 10:50 PM
Putting Cursor in Cell A1 of each Worksheet, then ending cursor on smalest sheet name according to VBA Editor Matt Microsoft Excel Programming 1 14th May 2007 09:21 AM
Sheet protection error msg - Unrequested sheet activation deltree Microsoft Excel Programming 0 28th Jan 2004 06:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:55 AM.