Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ExcelMonkey wrote ...
I have a CSV File which I want to import into my spreadsheet. I have included the file in this posting. I use the following code below to pull in the entire file. It works great. It creates separate columns for the data items based on comma delimited logic. I want to update the code so that I can enter a query based on the items in column 1, 3 and 4. Column 1 has either "Offers" or "Bids" data. Note they are continuous. Column 3 has "date" data, and column 4 has "Hour" data (1-24). I want to be able to query on only the "Offers", for a given day in column 3 (ie. 01/01/2004) for a given hour in column 4. How do I do this? Open "c:\Documents and Settings\rkaczanowski.EDCASSOCIATES\Desktop\Histor ical_Trading_2004_01.CSV" _ For Input As #1 <SNIP You could do this with ADO and SQL: Option Explicit Const PATH As String = "" & _ "c:\Documents and Settings\rkaczanowski.EDCASSOCIATES\Desktop\" Const TABLE As String = "Historical_Trading_2004_01.CSV" Private Const CONN_STRING As String = "" & _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=<<PATH;" & _ "Extended Properties='Text;HDR=NO'" Sub TestLateBound() Dim oConn As Object Dim oRs As Object Dim strCon As String Dim strSql As String strCon = CONN_STRING strCon = Replace(strCon, "<<PATH", PATH) Set oConn = CreateObject("ADODB.Connection") With oConn .CursorLocation = 3 ' adUseClient .ConnectionString = strCon .Open End With strSql = "SELECT F1, F2, F3, F4" & _ " FROM " & TABLE & _ " WHERE F1='Offers'" & _ " AND F3=#01 JAN 2004#" & _ " AND F4=12" Set oRs = oConn.Execute(strSql) ActiveCell.CopyFromRecordset oRs oRs.Close oConn.Close End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Build a query from a web-based database or a PDF file. | Excel Discussion (Misc queries) | |||
Importing CSV file (saved as Text) into XL as Text -- over 60 colu | Excel Discussion (Misc queries) | |||
Importing text file, only option to edit existing file | Excel Discussion (Misc queries) | |||
Importing Text file based on criteria | Excel Discussion (Misc queries) | |||
importing text file, removing data and outputting new text file | Excel Programming |