+ Reply to Thread
Results 1 to 13 of 13

Query HUGE Excel Range With SQL

  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Query HUGE Excel Range With SQL

    I am trying to set up an SQL query of 2 HUGE excel ranges. My code is in the testing stage so the SQL statement is pretty stripped down. However, I am already getting errors.
    The following Code errors on the SQL statement if I make the range to 66K rows, It works fine on 65K. Why? My real range will be like 200K

    Please Login or Register  to view this content.
    also, i'd like to replace the hard keyed range with the range variable I set as TableA. I also set the sheet to a variable ws1. How can I use those instead of the hard keyed sheet name and range?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Query HUGE Excel Range With SQL

    The following Code errors on the SQL statement if I make the range to 66K rows, It works fine on 65K. Why? My real range will be like 200K
    Excel 2003 has a limit of 65,536 rows. I noticed in your signature you said you have Excel 2007, so you'll have to use that version as this has 1,048,576 rows available.

    i'd like to replace the hard keyed range with the range variable I set as TableA
    What part of the code do you want to use this range? The command to set the 'strSql' variable refers to a different tab name

    I also set the sheet to a variable ws1
    Assuming this tab will be the first tab (i.e. furtherest left of all tabs (hidden and unhidden)) in the workbook, you can use this:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Query HUGE Excel Range With SQL

    I am using 2007, which is why I don't get why there is an issue. It errors out??

    I was able to address the SQL sheet/table issue as follows:
    Please Login or Register  to view this content.
    But if TableA contains to many rows...bam! Error, what gives??

    Error says Microsoft Access Database engine could not find object 'sheet1$H9:J200000'. Make sure object exist and you spell its name and path name correctly.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Query HUGE Excel Range With SQL

    But if TableA contains to many rows...bam! Error, what gives??
    Ah, there seems to be a SQL (64K) limit rather than an Excel limit on the number of rows that can be imported via this method (see here for more info and a potential workaround).

    Error says Microsoft Access Database engine could not find object 'sheet1$H9:J200000'
    At a guess I would say this is missing an exclamation, i.e. should be sheet1!$H9:J200000 If not, return the part of the code that works to a message box i.e. MsgBox TableA.Address(False, False) and note what is exactly needed.

    HTH

    Robert

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Query HUGE Excel Range With SQL

    Change the query to:
    Please Login or Register  to view this content.
    and it should work.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Query HUGE Excel Range With SQL

    hi, rock24, I hope this example will help you a bit
    Attached Files Attached Files

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Query HUGE Excel Range With SQL

    How will a 2003 format workbook assist with querying 66k rows?

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Query HUGE Excel Range With SQL

    what is the problem to amend range?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Query HUGE Excel Range With SQL

    The asker originally stated that the posted code works when specifying a range down to row 65000 but not if you specify row 66000.
    The code you provided won't work as it uses the Jet provider and specifies the Excel 8 BIFF format which is not applicable here.

  10. #10
    Registered User
    Join Date
    04-10-2009
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Query HUGE Excel Range With SQL

    Hi,

    I have had the same problem and solution posted by RS is working, but I have problem with using aliases. I need to create a joint query and need to use aliases. Can anyone help?

    Thanks

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Query HUGE Excel Range With SQL

    Hi and welcome to the forum.

    Unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  12. #12
    Registered User
    Join Date
    04-10-2009
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Query HUGE Excel Range With SQL

    Hi,

    I experimented with RS solution as below:
    Please Login or Register  to view this content.
    and seems to me that the last part of the code ' [H9:J65000]' is obsolete.
    Whatever you select as range constraint it always will show all rows. For example code
    Please Login or Register  to view this content.
    will give the sale result as
    Please Login or Register  to view this content.
    and as
    Please Login or Register  to view this content.
    Any other ideas how to tackle this issue?

    Thanks

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,282

    Re: Query HUGE Excel Range With SQL

    It seems you are correct - I must not have tested that very well. However, using:
    Please Login or Register  to view this content.
    works for me in 2007 and 2010 - although I am aware that having 2010 installed on the same machine may make a difference.

+ 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