+ Reply to Thread
Results 1 to 2 of 2

Lock and Unlock cells using VBA

  1. #1
    Peter
    Guest

    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. #2
    Dave Peterson
    Guest

    Re: Lock and Unlock cells using VBA

    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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1