Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query an Excel Database

Status
Not open for further replies.

robert693

Programmer
Jun 20, 2001
40
US
I want to know how I could set up a database in Excel and how to query it. Thank You
 
Your best bet bet would be to set up a database in another app, for example access and then use Microsoft Query to query that database.
Go to Data, then get External Data, or use a Pivot Table.(Make sure you have MS Query installed)
 
An alternative, keeping it within Excel, is to type headings on the first row, then add data below. Don't skip columns or rows. Very simple.

Use the Data Filter to query the data, which "hides" records that do not match. This is often all that is needed to analyse data.

As a tip, place a formula like =SUBTOTAL(9,B10:B1000) above your heading row. Then as the filter is turned on and queried, you will see totals for only the selected data.
 
Hi Robert,

If the Data-Filter option is not appropriate, here is a brief example of the code required for extracting data from an Excel database:

Range("database").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:="criteria", _
CopyToRange:=Range("ext_out"), _
'Note:"ext_out" is an 'output' range on a separate sheet
Unique:=False

A couple of notes:

1) The names in quotes (e.g. &quot;database&quot;) are arbitrary &quot;Range Names&quot; which you can freely assign - by using Control <F3> and specifying the range.

2) The output range can be on any sheet, providing that the range name is UNIQUE to the workbook. Excel allows for more than one instance of the same range name. (Excel should NOT allow for more than one identical name, but it does.) The first identical range name created (of two or more) by default becomes the &quot;global&quot; workbook range name, whereas any additional identical range names are only &quot;sheet&quot; names
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top