Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Macro for locking cells after worksheet is protected

I have set up a sheet with some protected and unprotected cells. I then
created a macro to protect cells after user makes an entry. The macro works
ok at this point. I then protect the sheet and the macro does not work.
It gives me error 1004.
I am using ActiveCell.Locked = True and I have tried various combinations
with other functions.
I have also allowed macros to run.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro for locking cells after worksheet is protected

The worksheet should be unprotected when you change the locked property.

Activesheet.Unprotect Password:="ABC"
ActiveCell.Locked = True
Activesheet.Protect Password:="ABC"


--
Regards,
Tom Ogilvy


"Hugo" wrote:

I have set up a sheet with some protected and unprotected cells. I then
created a macro to protect cells after user makes an entry. The macro works
ok at this point. I then protect the sheet and the macro does not work.
It gives me error 1004.
I am using ActiveCell.Locked = True and I have tried various combinations
with other functions.
I have also allowed macros to run.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Macro for locking cells after worksheet is protected

If I remember right, before you can manipulate locking and unlocking
cells, your sheet has to be unprotected. So, to do what you describe,
you'd have to unprotect the sheet, lock the cell, then protect the
sheet.


Hugo wrote:
I have set up a sheet with some protected and unprotected cells. I then
created a macro to protect cells after user makes an entry. The macro works
ok at this point. I then protect the sheet and the macro does not work.
It gives me error 1004.
I am using ActiveCell.Locked = True and I have tried various combinations
with other functions.
I have also allowed macros to run.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Macro for locking cells after worksheet is protected

Great!!!!

Just one more thing to make my day perfect..

At the moment, the user has to press "Enter" and then Ctrl+Q (to run macro)==

ActiveSheet.Unprotect Password:="test"
ActiveCell.Offset(-1, 0).Select
ActiveCell.Locked = True
ActiveSheet.Protect Password:="test"
Save

So the active cell goes back up to lock the correct cell. Is there a way to
select the cell after the user types without having to press enter?

Many, many thanks....

Hugo
"Tom Ogilvy" wrote:

The worksheet should be unprotected when you change the locked property.

Activesheet.Unprotect Password:="ABC"
ActiveCell.Locked = True
Activesheet.Protect Password:="ABC"


--
Regards,
Tom Ogilvy


"Hugo" wrote:

I have set up a sheet with some protected and unprotected cells. I then
created a macro to protect cells after user makes an entry. The macro works
ok at this point. I then protect the sheet and the macro does not work.
It gives me error 1004.
I am using ActiveCell.Locked = True and I have tried various combinations
with other functions.
I have also allowed macros to run.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Macro for locking cells after worksheet is protected

How about not selecting the cell at all, but simply locking it?

Rather than:

ActiveCell.Offset(-1, 0).Select
ActiveCell.Locked = True

Just use:
Activecell.Offset(-1,0).Locked=True


To my knowledge, you can't run a macro while still typing in a cell, so
no matter what the user will either have to hit Enter before the macro
can be run.

If the above doesn't work, please explain a little more detail on the
big picture of what you're trying to do. Perhaps there's an easier way
rather than Ctrl+Q every time the user types something in a cell, like
a one-time macro that will lock every cell that's been typed in or
something.

Hugo wrote:
Great!!!!

Just one more thing to make my day perfect..

At the moment, the user has to press "Enter" and then Ctrl+Q (to run macro)==

ActiveSheet.Unprotect Password:="test"
ActiveCell.Offset(-1, 0).Select
ActiveCell.Locked = True
ActiveSheet.Protect Password:="test"
Save

So the active cell goes back up to lock the correct cell. Is there a way to
select the cell after the user types without having to press enter?

Many, many thanks....

Hugo
"Tom Ogilvy" wrote:

The worksheet should be unprotected when you change the locked property.

Activesheet.Unprotect Password:="ABC"
ActiveCell.Locked = True
Activesheet.Protect Password:="ABC"


--
Regards,
Tom Ogilvy


"Hugo" wrote:

I have set up a sheet with some protected and unprotected cells. I then
created a macro to protect cells after user makes an entry. The macro works
ok at this point. I then protect the sheet and the macro does not work.
It gives me error 1004.
I am using ActiveCell.Locked = True and I have tried various combinations
with other functions.
I have also allowed macros to run.


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 all but a few cells on a worksheet JC Excel Worksheet Functions 4 April 4th 23 11:29 AM
Edit text format in non-protected cells in protected worksheet Bonnie Excel Discussion (Misc queries) 2 April 19th 08 04:48 PM
How can I have formatting options like merge cells ,Bold,active for the unlocked cells of the protected worksheet.Is it possible in excel? divya Excel Programming 2 July 20th 06 02:04 PM
Locking cells with a checkbox using a macro. SplatterKat Excel Programming 1 June 9th 06 01:16 AM
Copying a worksheet witrh protected cells to a new worksheet John Excel Worksheet Functions 2 February 1st 06 02:19 PM


All times are GMT +1. The time now is 03:32 PM.

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

About Us

"It's about Microsoft Excel"