+ Reply to Thread
Results 1 to 5 of 5

Called a sub twice, failed in 2nd call, why?

  1. #1
    Registered User
    Join Date
    02-12-2006
    Posts
    54

    Called a sub twice, failed in 2nd call, why?

    Hello

    I have 4 worksheets, and when I want to open my workbook I want to protect them in a certain manner. I wrote the following sub that will protect any sheet I want when I call it and pass the sheet name to it:

    Please Login or Register  to view this content.
    Note: the variable UnlockedCell is a public string that has the value "A1".

    So, when I call this sub, I do so like this:

    Please Login or Register  to view this content.
    The problem now is: The (SetProtection Sheet1) runs successfully, however, when it comes to run the second call (SetProtection Sheet2) it stops at the following line (TargetSheet.Range(UnlockedCell).Select) and gives me an error that says "run-time error 1004... the select method of the range class failed"

    Someone might ask and say how I knew it referred to the 2nd call, and my answer is "I made a step-by-step debugging and that's where it stopped and gave me the error."

    So does anyone know why and help me out with it plz

  2. #2
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    What does your variable UnlockedCell refer to?

    If you're not updating it correctly -- for example, it may refer to a location on Sheet1 -- on your second pass you're trying to select a cell on a sheet where you've already (on your first pass) indicated that you should not be able to select any cells. (xlNoSelection)

    That's all I can come up with without more info.

    Scott

    Oops... missed your note.
    Last edited by Maistrye; 11-25-2006 at 02:22 AM.

  3. #3
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by cgi_pro
    Hello

    I have 4 worksheets, and when I want to open my workbook I want to protect them in a certain manner. I wrote the following sub that will protect any sheet I want when I call it and pass the sheet name to it:

    Please Login or Register  to view this content.
    Note: the variable UnlockedCell is a public string that has the value "A1".

    So, when I call this sub, I do so like this:

    Please Login or Register  to view this content.
    The problem now is: The (SetProtection Sheet1) runs successfully, however, when it comes to run the second call (SetProtection Sheet2) it stops at the following line (TargetSheet.Range(UnlockedCell).Select) and gives me an error that says "run-time error 1004... the select method of the range class failed"

    Someone might ask and say how I knew it referred to the 2nd call, and my answer is "I made a step-by-step debugging and that's where it stopped and gave me the error."

    So does anyone know why and help me out with it plz
    Hi,

    Just a guess, but was Sheet1 your activesheet when you ran the sub?

    if so, would an '.Activate' (or .select) before the first line work?

    ---
    Si fractum non sit, noli id reficere.

  4. #4
    Registered User
    Join Date
    02-12-2006
    Posts
    54
    Thankx a lot Bryan Hessey
    Your hint of activating a sheet before selecting any of its cells made it work for me

  5. #5
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by cgi_pro
    Thankx a lot Bryan Hessey
    Your hint of activating a sheet before selecting any of its cells made it work for me
    Hi,

    Good to see, and thanks for the response

    ---

+ 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