+ Reply to Thread
Results 1 to 3 of 3

Code locks cells when inserted in sheet module but returns error in standard module

  1. #1
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Code locks cells when inserted in sheet module but returns error in standard module

    Hi all,

    Currently, my code locks cells depending on the value of a specific cell in Range("D52:O52"). When this code is inserted into the sheet module it works perfectly. At present this is OK, as I run the main locking code from the standard module which calls each piece of code from each sheet to lock it. However, this looks messy when the users click on the macro section in developer tool bar and see sheet1.LockUnlock

    I decided to remove all the code from the sheet modules and place it in the same standard module as the parent locking code as a private sub (so I could still call it whilst it removed all references to sheet1.LockUnlock from the macro section in the developer tool bar)

    The only problem here is that I now get Unable to set the locked property of the range class. It is exactly the same code which works when inserted into the correct sheet module. If anyone could offer any assistance with this I would greatly appreciate it. Please see code below.

    Regards,

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Code locks cells when inserted in sheet module but returns error in standard module

    Hello yoda66,

    The problem was with the With ... End With construct. Any element that belongs to the object following With must be prefixed with a period. The other problem was the Sub needs to [bPublic[/b] to allow all code in the workbook to access the macro.

    The code below has all the changes made.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Code locks cells when inserted in sheet module but returns error in standard module

    Thanks very much - works perfectly. Nice simple fix

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Why do I get an error when running the code for an UserForm from a standard module?
    By kjy1989 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-24-2013, 01:50 AM
  2. userform event handling within a standard code module?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2010, 01:01 PM
  3. how to access Sheet module, normal module, Worbook module to type code
    By alibaba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2009, 07:51 AM
  4. [SOLVED] Running Standard Module Code from Dataform
    By Jim May in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2005, 12:05 PM
  5. Replies: 1
    Last Post: 04-10-2005, 07:07 PM

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