+ Reply to Thread
Results 1 to 9 of 9

Error: "Method 'Range' of object '_Global' failed"

  1. #1
    Registered User
    Join Date
    09-23-2009
    Location
    ~100 ft ASL (for now)
    MS-Off Ver
    Excel 2007 (was 2002)
    Posts
    23

    Error: "Method 'Range' of object '_Global' failed"

    Hi Folks,
    I'm so new to VBA this is probably another simple question, but here goes...

    The error-text is:
    "Method 'Range' of object '_Global' failed"

    It happens at:
    rng = Range(gCSchedule.Ws.Cells(gCSchedule.DateRow, StartCol))
    See following code...

    (Thanks in advance!)


    Please Login or Register  to view this content.


    I can supply more code, but note (in "Headings_Write") that the first "rng = Range" assignment works - the second one doesn't.
    Again, thanks!
    Last edited by dblword; 09-26-2009 at 04:36 PM. Reason: Solved

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: [yet another] "Method 'Range' of object '_Global' failed"

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here



    What are the values of the variables when the code fails?

    gCSchedule.DateRow =?
    StartCol=?
    gCSchedule.Ws.Cells(gCSchedule.DateRow, StartCol)=?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: [yet another] "Method 'Range' of object '_Global' failed"

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    You should also consider putting a proper location in your details - "funny" ones don't help you, the idea is we can see if a user migh have problems because English is not the irst language.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    09-23-2009
    Location
    ~100 ft ASL (for now)
    MS-Off Ver
    Excel 2007 (was 2002)
    Posts
    23

    Re: Error: "Method 'Range' of object '_Global' failed"

    Thanks for your patience, folks.

    Will have to byte-the-bullet and learn how to use the debugging tools so to report variable values. Please note: the first "rng = Range..." command results in date-value appearing exactly where expected, demonstrating ability to resolve gCSchedule.Ws.Cells and correctness of StartCol.

    One additional piece of info, the two-cell version of Range function - that is Range(Cells(1,1),Cells(1,1)) - seems to avoid the error, now am working on a different error.

    Range(Cells(1,1),Cells(1,1)).Locked = False
    throws
    "Unable to set the Locked property of the Range class"

    Again, thanks for your help (and patience.)

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Error: "Method 'Range' of object '_Global' failed"

    hi,

    Range(Cells(1,1),Cells(1,1)).Locked = False
    throws
    "Unable to set the Locked property of the Range class"
    This error will occur if the sheet is protected.

    If this answers your last question & you have solved your previous questions in this thread by yourself, can you please mark this thread as solved & ask any further questions in a new thread?

    hth
    Rob
    Last edited by broro183; 09-26-2009 at 02:39 PM. Reason: To clarify which question I am answering.
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  6. #6
    Registered User
    Join Date
    09-23-2009
    Location
    ~100 ft ASL (for now)
    MS-Off Ver
    Excel 2007 (was 2002)
    Posts
    23

    Error: (now) "Unable to set the Locked property of the Range class

    Hi Rob,
    Thanks for replying.
    Please note the protect = False instruction in class_initialize - this seems to be working. After the error ("Unable to set the Locked property of the Range class") when I manually check Tools\Protection, I see the option to "ProtectSheet". If I comment-out the line causing the error, constructor runs to completion, resulting sheet is protected, and I see Tools\Protection\"UnprotectSheet".

    I've tested with 1 sec delay after set protect = false, but no luck.

    If sheet is protected at time of error, I don't know what more to do to "Unprotect" it.

    Follow-up: Looks like this error can also occur if working with merged cells. (note call to DateMerge, in constructor, immediately after set protect = False. (scroll-down in code window.)

    Thanks/Cheers!
    Last edited by dblword; 09-26-2009 at 04:22 PM. Reason: New information

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Error: "Method 'Range' of object '_Global' failed"

    hi,
    I'll have a go at answering this, but if it doesn't work, can you please attach your workbook with no confidential data?
    (We can't tell what you've changed since posting the original code & with the whole file in front of us - something may stand out & bop us on the noggin saying look at me!)

    You're looking in the right place but if you record a macro of your actions you'll see that you need to change
    Please Login or Register  to view this content.
    btw, it is often a good idea to explicitly declare the workbook and worksheets when using Range or Cells because they will otherwise default to the activesheet which may not be your intent & can cause havoc.

    hth
    Rob

  8. #8
    Registered User
    Join Date
    09-23-2009
    Location
    ~100 ft ASL (for now)
    MS-Off Ver
    Excel 2007 (was 2002)
    Posts
    23

    Re: Error: "Method 'Range' of object '_Global' failed"

    Hi Rob,
    btw, it is often a good idea to explicitly declare the workbook and worksheets when using Range or Cells because they will otherwise default to the activesheet which may not be your intent & can cause havoc.
    Thanks, you're right on - Was running with Book1 also open - which was contributing to problems.

    Thanks/cheers

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Error: "Method 'Range' of object '_Global' failed"

    Good as gold, thanks for the feedback, marking the post as solved & adding to my rep'

    Rob

+ 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