Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default loading text file partially

Dear all,

Is it possible to load partially a text file depending on specific
criteria in it ?

Example:

text file contains (delimitor is ^)

aaaaa^bbbbbbb^ccccc^^eeeee^fffff
rrrrrr^eeee^ssssss^bbbb^jjjjj^ooooooo
kk^^mmm^hhhhhhhhhhhhhh^uuuuuuu^wwwwww
xxx^pppp^qqqq^bbbb^yyyyy^kkkkk

I want to load into excel only the records that contains "bbbb" in the
4th field (column)
so in this example only record 2 and 4 should be loaded.

Any way to achieve this ?

Many thanks in advance !

Ronald.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default loading text file partially

Maybe you can open the text file into another workbook/worksheet (just use
file|Open). Then you could parse your data (delimited) to separate the fields.

Add a header row if you need to.

Then apply data|filter|autofilter and show only the bbbb rows. C

Then copy those visible cells to the real location.

Close the imported workbook without saving.

" wrote:

Dear all,

Is it possible to load partially a text file depending on specific
criteria in it ?

Example:

text file contains (delimitor is ^)

aaaaa^bbbbbbb^ccccc^^eeeee^fffff
rrrrrr^eeee^ssssss^bbbb^jjjjj^ooooooo
kk^^mmm^hhhhhhhhhhhhhh^uuuuuuu^wwwwww
xxx^pppp^qqqq^bbbb^yyyyy^kkkkk

I want to load into excel only the records that contains "bbbb" in the
4th field (column)
so in this example only record 2 and 4 should be loaded.

Any way to achieve this ?

Many thanks in advance !

Ronald.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default loading text file partially

First of all many thanks for you reply!

I'm aware of that option.
Int that case you need to load all of the records.
My idea was, if you can decide at the moment you load the record, if
it should be put in the sheet or not it will decrease the 'mass load'
when the text file contains a lot of records...

regards,

Ronald.

  #4   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 145
Default loading text file partially

open the text file, read it in line by line, use Split(line,"^") to create
an array, check the 4th value

dim arr as variant


'read line
arr = Split(sLine, "^")

'array is zero-based so check element 3
if arr(3) = "bbbb" then
'write to sheet
end if
'loop



Tim



wrote in message
ups.com...
Dear all,

Is it possible to load partially a text file depending on specific
criteria in it ?

Example:

text file contains (delimitor is ^)

aaaaa^bbbbbbb^ccccc^^eeeee^fffff
rrrrrr^eeee^ssssss^bbbb^jjjjj^ooooooo
kk^^mmm^hhhhhhhhhhhhhh^uuuuuuu^wwwwww
xxx^pppp^qqqq^bbbb^yyyyy^kkkkk

I want to load into excel only the records that contains "bbbb" in the
4th field (column)
so in this example only record 2 and 4 should be loaded.

Any way to achieve this ?

Many thanks in advance !

Ronald.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default loading text file partially

Sub loadBBB(textFile As String, sheet As Worksheet)
Dim InputData As String
Dim i As Long
Dim sArray As Variant
Open textFile For Input As #1
i = 1
While Not EOF(1)
Line Input #1, InputData
sArray = Split(InputData, "^")
If "bbbb" = sArray(3) Then
sheet.Cells(i, 1).Value = InputData
i = i + 1
End If
Wend
Close #1
End Sub

Sub testLoadBBB()
Dim book As Workbook
Dim sheet As Worksheet
Set book = ThisWorkbook
Set sheet = book.Sheets("Sheet1")
sheet.Select
Selection.Clear
Dim filePath As String
filePath = "C:\code\input_file.txt"
loadBBB filePath, sheet
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default loading text file partially

Use a query, with suitable SQL SELECT.

NickHK

wrote in message
ups.com...
Dear all,

Is it possible to load partially a text file depending on specific
criteria in it ?

Example:

text file contains (delimitor is ^)

aaaaa^bbbbbbb^ccccc^^eeeee^fffff
rrrrrr^eeee^ssssss^bbbb^jjjjj^ooooooo
kk^^mmm^hhhhhhhhhhhhhh^uuuuuuu^wwwwww
xxx^pppp^qqqq^bbbb^yyyyy^kkkkk

I want to load into excel only the records that contains "bbbb" in the
4th field (column)
so in this example only record 2 and 4 should be loaded.

Any way to achieve this ?

Many thanks in advance !

Ronald.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default loading text file partially

Tim, Gimme,

Many thanks for your help, will test this right away !!

NickHK,

Sorry, don't have sql functionality on excel....

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default loading text file partially

Yes you do. dataImport External DataNew Database Query

NickHK

"Ronald" wrote in message
ps.com...
Tim, Gimme,

Many thanks for your help, will test this right away !!

NickHK,

Sorry, don't have sql functionality on excel....



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default loading text file partially

Tim, Gimme,

Works perfect, thanks !!!
It didn't at the beginning but that was because the array (sArray)
starts at 0 and not at 1.
Therefor my criteria was on the field before the one I wanted to
check.

again, many thanks !

Ronald.

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
How format partially one text cell for font, etc., but not whole c Nicole Excel Discussion (Misc queries) 2 July 9th 08 09:38 PM
vba to detect if column contains partially hidden text dk Excel Programming 3 October 12th 06 03:53 AM
loading a ocx file VBAfunkymonk Excel Programming 1 June 6th 05 01:06 PM
Count rows in text file by loading into array L Mehl Excel Programming 5 September 11th 04 07:15 AM
Loading text file Clayton L. Wilson Excel Programming 3 July 22nd 03 03:28 PM


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