Consulting

Results 1 to 3 of 3

Thread: Solved: Excel ADODB worksheet

  1. #1

    Solved: Excel ADODB worksheet

    Hi everyone

    I have question on ADODB and VBA, was wondering whether there was a way to have a variable worksheet name using ADODB. I am quite new to using ADODB could not find the answer on the web

    sSQL = "SELECT * FROM [WORKSHEET$A1:gL1000]"

    So, for the code above WORKSHEET is a reference to another worksheet name. So WORKSHEET maybe "WS1" or "WS2" rather then grab data from sheet called "WORKSHEET" (i hope that makes sense)?

    Thanks

    artrookie

  2. #2
    Put the sheet name in a variable called sSheetName and use that:

    sSheetName = "Sheet29"
    sSQL = "SELECT * FROM [" & sSheetName & "!$A1:gL1000]"

    Note that I added an exclamation mark, but maybe it isn't needed in this SQL statement.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    It works - thanks for quick reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •