![]() |
Selective import from CSV
Hi!
I am writing a macro to import certain *.csv files to Excel. Each line in the csv files represents a record. I wish Excel to import the records only if it founds certain keywords. Can anyone suggests me which sets of commands I can use to do the things above? Million thanks!!! |
Selective import from CSV
It is really easy to import *all * the records and delete the ones you
do not want. --- Message posted from http://www.ExcelForum.com/ |
Selective import from CSV
The problem is each CSV file consist of over 100,000 records . . .
"BrianB " wrote in message ... It is really easy to import *all * the records and delete the ones you do not want. --- Message posted from http://www.ExcelForum.com/ |
Selective import from CSV
This works well by me :
Sub readFromCSV() Dim oCnn As Object Dim oCat As Object Dim oRs As Object Dim strPath As String, strFileName As String, strSQL As String Set oCnn = CreateObject("ADODB.Connection") Set oRs = CreateObject("ADODB.Recordset") strPath = "D:\" 'this is the path to file strFileName = "a.csv" 'name of the file strSQL = "SELECT * FROM " & strFileName & " WHERE Field1 = 'x'" oCnn.Open _ "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & strPath ";Extensions=asc,csv,tab,txt" oRs.Open strSQL, oCnn With oRs While Not .EOF 'here code for insertion to worksheet '... oRs.movenext Wend End With oRs.Close oCnn.Close End Su -- Message posted from http://www.ExcelForum.com |
Selective import from CSV
|
Selective import from CSV
The reason I don't use Access is because I need to do some mathematical
analysis with the data. I also need to filter out some of the unwanted records . . . if I do it manually it will take me at least 1 hr per each of the hundreds CSV files. "BrianB " wrote in message ... <<over 100,000 records MS Access then ? --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 02:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com