+ Reply to Thread
Results 1 to 21 of 21

Run-time error '1004' Unable to set the Locked Property of the Range Class

  1. #1
    Registered User
    Join Date
    03-02-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Run-time error '1004' Unable to set the Locked Property of the Range Class

    I keep getting the following error message:

    Run-time error '1004' Unable to set the Locked Property of the Range Class

    I want to unlock the cell if the checkbox is checked and when it is not I want to set the cell to a formula and lock it.

    Please help

    Please Login or Register  to view this content.
    Thank you

  2. #2
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    You realise you are referencing two different sheets there? Sheet1 and Check_Box - was this intended?

  3. #3
    Registered User
    Join Date
    10-08-2009
    Location
    Hull, England
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    73

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    As above seems you made a small slip up in your code.
    Check and fix
    Any more help needed tell us what line it errors on.
    Like my post? Considered leaving Rep? Thanks.

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    I think this is what you intended:

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Registered User
    Join Date
    03-02-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Thank you very much for your input. I copied abousetta's code and I am still getting the run time error. Do you have any other ideas?

  6. #6
    Registered User
    Join Date
    10-08-2009
    Location
    Hull, England
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    73

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Do you know at what line you are getting the error?
    Please open your Visual Basic Window, select the Starting sub line of the Macro and being to Press F8, this will run the macro step by step, tell us where you gain an error.

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Hi,

    I tried both methods of locking/ unlocking (e.g. with and without parentheses around the password and both work. Therefore I am assuming it is something else that it triggering this error. I am guessing its this line:

    Please Login or Register  to view this content.
    It looks like this is a UDF, in which case Rory is definitely correct.

    Jerums can you confirm which line the error message is highlighting.

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Removing the parens was just force of habit as it's bad practice to use them there (and it bugs me).
    The formula was the main correction.
    Good luck.

  9. #9
    Registered User
    Join Date
    03-02-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Thank you for your help. I am getting a couple of things. When the error pops up and I click "Debug" the highlighted code is
    Please Login or Register  to view this content.
    Also the SpigDiam function is not working.It will highlight BB5 and say "Compile error: ByRef argument type mismatch"

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    @ OnErrorGoto0,

    Well spotted Rory! You deserve a good rep!
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    A few questions:
    1. Which code are you using?
    2. Which sheet are you trying to alter?
    3. Are you trying to enter a formula including SpigDia, or a value using the SpigDia function?

  12. #12
    Registered User
    Join Date
    03-02-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    The code I am using is below:

    Please Login or Register  to view this content.
    I am getting the error on the line ".Range("BB9").Locked =True"

    The SpigDia function is working. I know this because if I unlock Cell "BB9" before I run the code it works fine (except for locking or unlocking the cell). But when I start with the cell locked I get the error.

    Thank you for your help.

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Could you please upload a sample WorkBook of your problem, so that we can take the guessing out of possible solutions.

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    I think you may be using the wrong password then.

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    @ OnErroGoto0,

    It is either that, or the wrong Sheet.

  16. #16
    Registered User
    Join Date
    02-12-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Here is the solution. I am a beginner with VBA and far far far from being a Guru. But I had the same problem and spend 2 days over the internet to find the solution. It has something to do with Merged Cells (Excel which is a product of Microsoft - a corporation who does not give a ***** about its clients) did not bother to tell anybody about the merged cell problem.
    Well I used to have
    .Range("D4").Locked = True Which gave me a 1004 error continuosly
    Now I changed it to
    .Range("D4").MergeArea.Locked = True and it is working !!!!!

  17. #17
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Thanks for sharing the solution. I've never heard of .mergearea before and I learned something new today. In general lots of problems happen with merging and so I tend to try and stay away from that.

    Glad you found a solution.

    abousetta

  18. #18
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    Hello upsipo,

    Thank you for sharing the solution with the Forum.

    I am sure a lot of us appreciate it.

    As abousetta says:

    I've never heard of .mergearea before and I learned something new today.

  19. #19
    Registered User
    Join Date
    02-12-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    When I was a programmer Analyst with IBM MainFrame, front end CICS, Cobol. It might require you to code 5 times more lines than maybe VBA , but everything was clear, known in advance, with no surprizes. VBA , Csharp and all those new languages, require a huge level of expertize, code is criptic , and even the author can not understand what he wrote later on, let alone somebody else. From a community of 100% Excel VBA programmers , Just very few can code REAL VBA functional code. The code realisticly CAN NOT be maintained later on by somebody else. If you are realistic, on the Mai9nframe it will take you 1/2 of the time to develop an application. Yes I am frustrated, I managed to code wonder code in VBA Excel in just 3 weeks, from scratch. But to become a guru like yourself, it will take me years... Thank you, (no need to reply unless you enjoy the conversation...).

  20. #20
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    I'm not standing up for MS or for VBA (which is outdated and is missing basic capabilities according to today's standards). If you go back to a few years, I never programmed anything in VBA, or any other language for that matter, so I can't really compare.

  21. #21
    Registered User
    Join Date
    02-12-2013
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Run-time error '1004' Unable to set the Locked Property of the Range Class

    I studies before C# (C sharp) and C and C++, they are all the same, somewhat better then VBA (C# through Visual Studio) - because I wanted to beat the stock market. After the end of the project (which was a failure anyway, because you can not beat the sharks on wallstreet, I discovered that I could have done the same very thing with the antiquated Cobol2 (which has function capabilities) it would have taken me 5 times more code with Cobol but the debbuging would be a piece of cake. (IBM IS NOT repeat is not MicroSoft) And if you look at the code 10 years later, you WILL UNDERSTAND what you wrote. In the early eighties, there was an operating system on PC by IBM, it was called DB2pc or something like that, DOS operating systems with point and click which Microsoft lounched was Full of bugs, but it was "nice" click and point, so the world is left with all the garbage now. Ofcource people will tell you "do not listen to this expired dinosour old man (me). I have heard many talks about Object oriented code, in theory maybe, but try to ask a Guru what is object oriented code? They do not know themselves. Anyway, happy ending, I am a landloard now, and out of the USA (which btw, is going down the tube). With those "encouraging" words, I wish you a good night from Europe, and thanks for the chit chat.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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