+ Reply to Thread
Results 1 to 9 of 9

Method 'Range' of object '_Worksheet' failed

  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    59

    Method 'Range' of object '_Worksheet' failed

    Hey,

    I can't seem to figure out why this keeps giving me that error...

    I've checked the row and column values inside and they seem to be ok. blank_ee() is an array of strings

    Please Login or Register  to view this content.
    I'm not sure what I'm missing. Seems like it should be a simple problem, but I can't seem to find it.

    Thanks for all your help.
    Last edited by Kaigi; 06-24-2009 at 11:14 AM.

  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: Method 'Range' of object '_Worksheet' failed

    Hello Kaigi,

    The array blank-ee has to return a string variable that represents an Excel worksheet address, like "A1:G50".
    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
    06-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    59

    Re: Method 'Range' of object '_Worksheet' failed

    Thanks for the tip. I do believe that is the case though...

    blank_ee(1...3) = "$I:$16", "$I:$17", and "$I:$75" respectively.

    All the .row and .column calls seem to give what I expect so I don't understand why I'm still getting this error.

    One thing I've seem to notice is that sometimes, after fiddling with the line a bit (but not actually changing anything) it works. But then I go to run it again and the error comes back. Any ideas on why that might happen?
    Attached Images Attached Images
    Last edited by Kaigi; 06-24-2009 at 09:47 AM.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Method 'Range' of object '_Worksheet' failed

    I suspect you want:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    06-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    59

    Re: Method 'Range' of object '_Worksheet' failed

    Oh wow that works. I've seen the With...End notation before, but I don't understand how its different from what I had previously.

    Could you tell me why what you gave me worked and what I had didn't?

    Thanks for all your help!

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Method 'Range' of object '_Worksheet' failed

    Assuming your code was in a normal module, then it would only have worked when ws5 was the active sheet. In this code:
    Please Login or Register  to view this content.
    the red parts are not qualified with a worksheet object. In the With...End With construct I posted, you will see they are preceded by a period which makes them properties of the ws5 object.

  7. #7
    Registered User
    Join Date
    06-03-2009
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    59

    Re: Method 'Range' of object '_Worksheet' failed

    oh... so I would have needed "ws5." in front of all the text that you marked as red.

    Wouldn't have thought that mattered since i specify ws5. in the beginning of the line for copy, but I guess its a lesson to me that it can matter.

    Thanks for the help and explanation.

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Method 'Range' of object '_Worksheet' failed

    Yes, you should qualify all properties/methods really unless you are sure the default behaviour is what you want (even then it might change in future versions!)
    Incidentally, if the code had been in a worksheet code module, those red highlighted words would have referred to the worksheet containing the code, not (necessarily) the active sheet or the sheet you wanted.

  9. #9
    Registered User
    Join Date
    08-07-2012
    Location
    Columbus, GA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Method 'Range' of object '_Worksheet' failed

    Qualifing each red area took care of my problem too. I had the exact same question.
    Thanks!

+ 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