Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CK CK is offline
external usenet poster
 
Posts: 5
Default 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!!!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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/

  #3   Report Post  
Posted to microsoft.public.excel.programming
CK CK is offline
external usenet poster
 
Posts: 5
Default 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/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Selective import from CSV

<<over 100,000 records

MS Access then

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
CK CK is offline
external usenet poster
 
Posts: 5
Default 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/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selective Validation WildWill Excel Discussion (Misc queries) 4 March 11th 09 10:33 AM
Selective on Name stew Excel Discussion (Misc queries) 5 September 14th 08 07:53 PM
Selective Trendlines Chad[_3_] Charts and Charting in Excel 2 July 19th 08 02:26 PM
Excel External Data Selective Import. Nitrox50 Excel Discussion (Misc queries) 0 January 20th 07 09:49 AM
selective averaging Wazooli Excel Worksheet Functions 3 December 10th 04 09:25 PM


All times are GMT +1. The time now is 04:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"