Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 334
Default ActiveSheet.QueryTables.Add

I am importing a CSV file and want to be selective in my data. I need to
bypass any record that does not have a char "V" in the specified column. The
above subject is also the standard QueryTables.Add statement. Any
suggestions?
--
Rick Rack
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default ActiveSheet.QueryTables.Add

Rick wrote:
I am importing a CSV file and want to be selective in my data. I need to
bypass any record that does not have a char "V" in the specified column.
The above subject is also the standard QueryTables.Add statement. Any
suggestions?


Rick: Unless I'm misunderstanding something, you can be selective with a
QueryTables.Add statement. You pass a SQL statement to QueryTables.Add and
use the SQL statement to limit the records it imports. Here's an example:

Sub AddQTFromCSV()

Dim sConn As String
Dim sSQL As String

sConn = "ODBC;DSN=Text Files;" & _
"DefaultDir=C:\Documents and Settings\Dick\My Documents;" & _
"DriverId=27;MaxBufferSize=2048;PageTimeout=5; "

sSQL = "SELECT Field1, Field2, Field3, Field4, Field5" & _
" FROM `C:\Documents and Settings\Dick\My Documents`\Book1.csv" & _
" WHERE (Field2='V')"

With Sheet3.QueryTables.Add(sConn, Sheet3.Range("A1"), sSQL)
.Refresh
End With

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.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
ActiveSheet.QueryTables.Add quartz[_2_] Excel Programming 0 November 9th 05 07:18 PM
help with ActiveSheet.QueryTables.Add Connection: uriel78 Excel Programming 1 March 6th 05 04:08 PM
ActiveSheet.QueryTables.Add using a File DSN Brian Howenstein Excel Programming 1 April 6th 04 11:45 AM
With ActiveSheet.QueryTables.Add [email protected] Excel Programming 4 January 6th 04 04:58 PM


All times are GMT +1. The time now is 04:18 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"