Using an Excel macro to query a spreadsheet
So I have开发者_运维知识库 some data in some spreadsheets and I've found that for all the macros and filtering and forumlas I've written to simplify it and narrow it down to what I want, it would have been much easier to just write some SQL against a few tables.
I guess I'm wondering: is it possible to have a macro in a workbook that queries data in some sheets and then populates another sheet with the result set? If so, how would I do it?
(It is Excel 2003)
No need for a macro for this.
Go to DATA-> Import External Data -> Import Data
then basically follow the prompts. You may need to make a new data connection, (New Source
at the bottom) but once connected you can write queries natively in Excel.
I'm guessing someone familiar with DBs would be able to figure it out pretty quickly. If not, here's a tutorial.
Why do you need to use a macro when you can simply query the excel file like this:
SELECT Column1, Cloumn2, Column3
FROM [SheetName$Range]
WHERE Condition
Example:
SELECT ProductID, Qty, Price
FROM [SheetName$A10:C21]
WHERE ProductID = 545
精彩评论