Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Peter
 
Posts: n/a
Default Lock and Unlock cells using VBA

Hello All
Anyone know how to lock cells using VBA, also unlock others currently locked.
Page protection will be in use at the time this needs to be done.

Also, is there anywhere on the net with a complete list of VBA functions,
including a short statement of what each one does, with or without examples.

If not, any good books that cover the above area. I'm really (strange as it
might seem), enjoying playing with VBA and seeing exactly what it can do.

Regards
Peter
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

The easy questions...

Excel's Help is a very good source.

take a look at Peter Nonely's workbook that describes lots of functions:
http://homepage.ntlworld.com/noneley/
Peter's site isn't working, but Ron deBruin has a copy at:
http://www.rondebruin.nl/files/xlfdic01.zip

Debra Dalgleish has some of Norman Harker's files at:
http://www.contextures.com/functions.html

Debra also has a list of books:
http://www.contextures.com/xlbooks.html

Lot's of people swear by John Walkenbach's books.

=======
You can record a macro in excel when you do this kind of stuff.

Turn on the macro recorder:
tools|macro|record new macro
unprotect the worksheet
change a cell from Locked to unlocked and a different cell from unlocked to
locked.
reprotect the workbook.
stop the recorder.

Inspect/generalize the code...

this was my recorded code:

Option Explicit
Sub Macro1()
ActiveSheet.Unprotect
Selection.Locked = True
Selection.FormulaHidden = False
Range("A24").Select
Selection.Locked = False
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Notice that the recorder doesn't display the passwords you entered.

One way of modifying the code is:

Option Explicit
Sub Macro1A
ActiveSheet.Unprotect password:="hi"
range("a1").Locked = True
range("a24").locked = false
ActiveSheet.Protect password:="hi",DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

But it would really depend on what cells are being locked/unlocked.


Peter wrote:

Hello All
Anyone know how to lock cells using VBA, also unlock others currently locked.
Page protection will be in use at the time this needs to be done.

Also, is there anywhere on the net with a complete list of VBA functions,
including a short statement of what each one does, with or without examples.

If not, any good books that cover the above area. I'm really (strange as it
might seem), enjoying playing with VBA and seeing exactly what it can do.

Regards
Peter


--

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
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM
To safety merge cells without data destroyed, and smart unmerge! Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:17 AM
Heps to design Locked/Unlocked cells in protected worksheet Kevin Excel Discussion (Misc queries) 0 December 30th 04 07:09 AM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM
Can a cell be locked to prevent being typed over? debbieah Excel Worksheet Functions 2 December 7th 04 04:37 PM


All times are GMT +1. The time now is 09:46 AM.

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"