If you want to do it SQL style, you can stick to the Excel spreadsheet and use it like a DB...if you dont do this often and performance or data security are not of the issue...
You need to connect to your "Excel DB" and then you can run all SQL queries you like.
The query below should be pretty close to what you want to do.
Where would your data be and what table to query? On your spreadsheet select the relevant data and give that range a name. Tada: your table name.
http://www.connectionstrings.com/?carrier=excel2007
http://www.connectionstrings.com/?carrier=excel
To connect:
Code:Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim rst as ADODB.recordset Dim strQry As String Set cnn = New ADODB.Connection cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" cnn.Open strQry = "SELECT * FROM myDataRange WHERE myField Like '*ABC*' Set cmd = New ADODB.Command Set cmd.ActiveConnection = cnn cmd.CommandType = adCmdText cmd.CommandText = strQry Set rst = New ADODB.Recordset Set rst = cmd.Execute 'manipulate write or do whatever to your data here rst.close set rst = nothing set cmd = nothing set cnn = nothing




Reply With Quote