Using SQL in Excel to Select from Cell value

Posted on 2010-01-08
Medium Priority
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

Expert Comment

by:Brad Sims, CCNA
ID: 26248132
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

ID: 26262563
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

hiteshgoldeneye earned 2000 total points
ID: 26269336

Author Comment

ID: 26273032
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

807 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