Using SQL in Excel to Select from Cell value

Posted on 2010-01-08
Last Modified: 2012-05-08
I am using some sql in a module in my Excel file and need to know if I need to Select a value from a cell in Sheet if that is possible using SQL?

Set RST = New ADODB.Recordset
 SQL = "SELECT  [Business Group Code], [Business Unit Code] FROM [AllData]"
RST.Open SQL, cn, adOpenStatic
Question by:Medicine1
    LVL 7

    Expert Comment

    Can you attach an example file so I can see exactly what you are looking for?  If you need to select a value from a cell it would seem easier to have VBA pull the value rather than writing a SQL query unless I'm misunderstanding the question.
    LVL 10

    Expert Comment

    You can do.  The trick is to have headers in the sheet - or have a named range...  then you can SQL query it as you would any other database table.

      Easiest way to see the syntax is to create a querytable using the wizard - and then use


    in your immediate window to get used to Excels table names and such.  Once you are used to that - yes you can just code your queries with SQL.

    LVL 13

    Accepted Solution


    Author Comment

    John15-16  = the example would be

    A                                        B
    Business Group              XYZ
    Business Unit                 ABC
    Business Org                  DCD      

    I understand the named ranged piece for having a table, but these will be row headings and that is why I am asking.  Can it be done with row headings?  

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This Article is a follow-up to my Mappit! Addin Article (, it was inspired by an email posting I made to EUSPRIG (, I will briefly cover: 1) An overvie…
    Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now