![]() RgPlaceOutput.Resize(20000, 6).ClearContents MsgBox "Your query could not be executed, the SQL-statement is incorrect."ĭim rgPlaceOutput As Range 'first cell for the output of the queryĭim stSQLstring As String 'text of the cell containing the SQL statement MsgBox "There is no records that matches the query !!", vbCritical 'if the recordset contains data put them on the worksheet RsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText 'Set up the connection string to excel against wbWorkbook Public Sub QueryWorksheet(szSQL As String, rgStart As Range, wbWorkBook As String)Īpplication.StatusBar = "Retrieving data. A query on 1 table with totals and a query that joins 2 tables.īe aware that the sample file is quite big. With SQL it is also possible to query data in a closed workbook. ![]() The code lets you write a a complex SQL statement directly in a cell and retrive the output where you want it. Using SQL directly in a worksheet as a powerful alternative to advanced filter, including the ability to join tables on two or more worksheets. This code provides the capability to enter SQL-statements in a cell and run the query against other sheets in the same workbook.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |