+ Reply to Thread
Results 1 to 8 of 8

vba a query to run in an excel sheet ..

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    45

    vba a query to run in an excel sheet ..

    Hi

    is it possible to use vba to run a query based on data in an excel sheet ?

    I have data which is identical in terms of the headings ,to the table i have in access just want the query to query my data instead of the tables data


    if so could someone help - plz also let me know if this is not possible

    regards

    silver
    Last edited by silverxx12; 06-21-2012 at 10:16 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: vba .. is this possible?

    I'm a little confused, what do you actually want to do?

    Run SQL commands on an Excel Spreadsheet?

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: vba .. is this possible?

    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.


  4. #4
    Registered User
    Join Date
    06-14-2012
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    45

    Re: vba a query to run in an excel sheet ..

    hope title is better sometimes its ahrd to know what you u r doing sry :-(

    yes i wish to run the sql query in my db based on the data i have in an excel worksheet

    hope that makes sense

    regards

    silver

  5. #5
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: vba a query to run in an excel sheet ..

    Hi

    Required - Excel 2007 NOT 2003

    Attached is a WB that

    1 - Uses ADO to talk to the WB

    2 - Uses SQL to get some records from 1 sheet to another

    What you have to do:

    1 - Modify the SQL (statement) to do what you want.

    e.g
    Select * from [Sheet1$]
    Select Lastname, Firstname from [Sheet1$] where ID > 10

    You can use Excel 2003 but then the provider info has to change.

    F8 thru the code to get the hang of it.

    Note:Using ADO against a WB introduces memory leaks (google)
    but it has never bit me yet.

    Try to stay away from the EXISTS thingie in SQL - its very slow.

    HTH
    John
    Attached Files Attached Files

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: vba a query to run in an excel sheet ..

    You only get memory leaks when querying the same workbook that the code is in, this is easy to get round by having the code in a separate workbook

  7. #7
    Forum Contributor
    Join Date
    12-26-2010
    Location
    Kansas City, Kansas
    MS-Off Ver
    Excel 2007
    Posts
    147

    Re: vba a query to run in an excel sheet ..

    Hi Kyle

    Good point!

    (but I've been guilty along time) -g-

    then he's going to have to change the FROM clause ??

    IN ['c:myDir\myWB.xlsx\'] ??
    IN [c:myDir\myWB.xlsx\] ??
    IN 'c:myDir\myWB.xlsx\' ??

    are any of those close - I don't remember - off top of head.

    regards
    John



    regards
    John

  8. #8
    Registered User
    Join Date
    04-16-2014
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    1

    Re: vba a query to run in an excel sheet ..

    Thanks John. Useful resource, crisp code.

+ 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