+ Reply to Thread
Results 1 to 8 of 8

Select method of range class failed error

  1. #1
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    185

    Select method of range class failed error

    When I try to run one of my macro, at the following line:
    Sheets("historical data").Range("O107").Select

    I get an error popup that says: Run time error 1004. select method of range class failed.

    Can someone please let me know what am I doing wrong? All I am trying to do is select cell O107 in sheet named "historical data" (I have checked that sheet name is correct).

    Thank you in advance
    Jay
    Last edited by sa02000; 04-07-2012 at 10:14 AM.

  2. #2
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: Select method of range class failed error

    Hi maybe the "historical data" sheet is not the active one during runnig the code (You can use select method only on active sheet) and other thing is that You do not have to select object to change this
    Last edited by tom1977; 04-06-2012 at 07:07 AM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

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

    Re: Select method of range class failed error

    Hi Jay

    To select a cell, the cell that is selected must be on the Activesheet. So to ensure it works you could use:

    Please Login or Register  to view this content.
    However, you rarely need to select anything to work with it - if you explain what you want to do we can probably suggest alternative (and better) ways to achieve it.
    For testing your Regular Expression patterns, try my Regular Expression Pattern Testing add-in!

    For notes on how to use it - see here.

  4. #4
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    185

    Re: Select method of range class failed error

    Thank you very much for quick responses. I am doing just some basic copy paste after running an API for one of the online brokers. Here is the code that I have so far below. I have also attached the file (original of which was provided by Interactive Brokers) but this file won't work without a valid connection to broker. I know I am not great at this programming so any suggestions to reduce this code and looping will be helpful otherwise I am sure I will figure it out in few years time

    Please Login or Register  to view this content.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Select method of range class failed error

    I took 1 section of your provided code.
    Please Login or Register  to view this content.
    Cleaned up it becomes and removes 7 select actions.
    Here are some copy and paste code examples

    Please Login or Register  to view this content.
    Last edited by davesexcel; 04-06-2012 at 08:44 AM.

  6. #6
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    185

    Re: Select method of range class failed error

    Thank you Dave. This sure looks lot more concise and reusable.

    When I run this, I get the following error for both of these two lines in the code

    Please Login or Register  to view this content.
    Run-time Error '91'
    Object variable or With block variable not set.

    Any idea what might be causing this?

    Thank you
    Jay

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Select method of range class failed error

    Is the sheet you want to copy from empty? I opened your workbook, ran my bit of the code and got the same error. Once I placed data on the sheet, the code worked fine.




    Maybe edit your copy and paste line in case yo have more then 65536 rows,

    Please Login or Register  to view this content.
    Last edited by davesexcel; 04-06-2012 at 11:02 AM.

  8. #8
    Forum Contributor
    Join Date
    10-03-2005
    Posts
    185

    Re: Select method of range class failed error

    You are right. There was no data, once I made sure I was getting data from their server it works perfectly.
    Thank you very much. Added to your reputation

    Jay

+ 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