Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Automate 'Difficult' importing text file

Hi guys
Trying to import a txt file that comes out like this:
------------------------------------------------
19:57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

19:57 The Meadows Race 2
No. Dog Price
1 Fido1 3.50
2 Brutus1 21.50
3 Smokin fast1 16.00

-------------------------------------------------


and convert like this:

The Meadows 1 1 Fido 3.50
The Meadows 1 2 Brutus 21.50
The Meadows 1 3 Smokin fast 16.00
and so....

in otherwords put the header of each dog race into a column field.
I can do it excel with about 2000 lines of if statements but can i do it in
access easier as i need to automate it as i have todo thousands of them.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Automate 'Difficult' importing text file

How are the columns separated ?
Spaces, Tabs
Or fixed width ?

i.e. How does the data appear when open in Excel ?

And, is there really a blank line between race data ?

NickHK

"MArk" wrote in message
...
Hi guys
Trying to import a txt file that comes out like this:
------------------------------------------------
19:57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

19:57 The Meadows Race 2
No. Dog Price
1 Fido1 3.50
2 Brutus1 21.50
3 Smokin fast1 16.00

-------------------------------------------------


and convert like this:

The Meadows 1 1 Fido 3.50
The Meadows 1 2 Brutus 21.50
The Meadows 1 3 Smokin fast 16.00
and so....

in otherwords put the header of each dog race into a column field.
I can do it excel with about 2000 lines of if statements but can i do it

in
access easier as i need to automate it as i have todo thousands of them.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Automate 'Difficult' importing text file

Thanks for reply Nick
It comes in Spaces, and there is a blank line between them.I have to use the
import wizard to line the columns up.

Field1 Field2 Field3
19: 57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

So thats how it comes out in excel.
I could do a simple left of cell B2 to just get 'the meadows' but problem
is sometimes the No. of runners is not consistent.


"NickHK" wrote:

How are the columns separated ?
Spaces, Tabs
Or fixed width ?

i.e. How does the data appear when open in Excel ?

And, is there really a blank line between race data ?

NickHK

"MArk" wrote in message
...
Hi guys
Trying to import a txt file that comes out like this:
------------------------------------------------
19:57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

19:57 The Meadows Race 2
No. Dog Price
1 Fido1 3.50
2 Brutus1 21.50
3 Smokin fast1 16.00

-------------------------------------------------


and convert like this:

The Meadows 1 1 Fido 3.50
The Meadows 1 2 Brutus 21.50
The Meadows 1 3 Smokin fast 16.00
and so....

in otherwords put the header of each dog race into a column field.
I can do it excel with about 2000 lines of if statements but can i do it

in
access easier as i need to automate it as i have todo thousands of them.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Automate 'Difficult' importing text file

What about dog names that contain spaces ? e.g. Smokin fast
Are they delimited with " ?

NickHK

MArk" wrote in message
...
Thanks for reply Nick
It comes in Spaces, and there is a blank line between them.I have to use

the
import wizard to line the columns up.

Field1 Field2 Field3
19: 57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

So thats how it comes out in excel.
I could do a simple left of cell B2 to just get 'the meadows' but problem
is sometimes the No. of runners is not consistent.


"NickHK" wrote:

How are the columns separated ?
Spaces, Tabs
Or fixed width ?

i.e. How does the data appear when open in Excel ?

And, is there really a blank line between race data ?

NickHK

"MArk" wrote in message
...
Hi guys
Trying to import a txt file that comes out like this:
------------------------------------------------
19:57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

19:57 The Meadows Race 2
No. Dog Price
1 Fido1 3.50
2 Brutus1 21.50
3 Smokin fast1 16.00

-------------------------------------------------


and convert like this:

The Meadows 1 1 Fido 3.50
The Meadows 1 2 Brutus 21.50
The Meadows 1 3 Smokin fast 16.00
and so....

in otherwords put the header of each dog race into a column field.
I can do it excel with about 2000 lines of if statements but can i do

it
in
access easier as i need to automate it as i have todo thousands of

them.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Automate 'Difficult' importing text file

See what you get from this. based on a certain amount of guesswork on the
original data file format.
As you (apparently) have location and dog names that can have spaces in
them, without them being delimited between "", it slightly complicates the
reading, but not much.

Private Sub CommandButton1_Click()
Dim FileNum As Long
Dim InData() As String
Dim i As Long
Dim TempData As Variant
Dim LastElement As Long
Dim j As Long
Dim EntryCount As Long

Dim StartRange As Range

Dim RaceData(1 To 5) As Variant
'1 - Location
'2 - Race Number at that location
'3 - Dog Number
'4 - Dog Name
'5 - Price
Const Location As Long = 1
Const LocationRaceNumber As Long = 2
Const DogNumber As Long = 3
Const DogName As Long = 4
Const DogPrice As Long = 5

Const FileName As String = "C:\DogRace.dat"
Const Delim As String = " "
Const RaceText As String = "Race"

Set StartRange = Worksheets(2).Range("A1")

FileNum = FreeFile

'Clear old data
Erase InData

Open FileName For Input As FileNum
InData = Split(Input(LOF(FileNum), #FileNum), vbNewLine)
Close FileNum

For i = LBound(InData) To UBound(InData)
TempData = Split(InData(i), Delim)
LastElement = UBound(TempData)
If InStr(1, TempData(LastElement - 1), RaceText) 0 Then
'Location data
Erase RaceData
For j = LBound(TempData) + 1 To LastElement - 2
RaceData(Location) = RaceData(Location) & " " & TempData(j)
Next
RaceData(Location) = Trim(RaceData(Location))

RaceData(LocationRaceNumber) = TempData(LastElement)
Else
'Dog Data
If IsNumeric(TempData(0)) = True Then
EntryCount = EntryCount + 1
RaceData(DogNumber) = TempData(0)

RaceData(DogName) = ""
For j = LBound(TempData) + 1 To LastElement - 1
RaceData(DogName) = RaceData(DogName) & " " & TempData(j)
Next
RaceData(DogName) = Trim(RaceData(DogName))

RaceData(DogPrice) = TempData(LastElement)

StartRange.Offset(EntryCount, 0).Resize(1, DogPrice).Value =
RaceData
End If
End If

Next

End Sub

NickHK

"MArk" wrote in message
...
Thanks for reply Nick
It comes in Spaces, and there is a blank line between them.I have to use

the
import wizard to line the columns up.

Field1 Field2 Field3
19: 57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

So thats how it comes out in excel.
I could do a simple left of cell B2 to just get 'the meadows' but problem
is sometimes the No. of runners is not consistent.


"NickHK" wrote:

How are the columns separated ?
Spaces, Tabs
Or fixed width ?

i.e. How does the data appear when open in Excel ?

And, is there really a blank line between race data ?

NickHK

"MArk" wrote in message
...
Hi guys
Trying to import a txt file that comes out like this:
------------------------------------------------
19:57 The Meadows Race 1
No. Dog Price
1 Fido 3.50
2 Brutus 21.50
3 Smokin fast 16.00

19:57 The Meadows Race 2
No. Dog Price
1 Fido1 3.50
2 Brutus1 21.50
3 Smokin fast1 16.00

-------------------------------------------------


and convert like this:

The Meadows 1 1 Fido 3.50
The Meadows 1 2 Brutus 21.50
The Meadows 1 3 Smokin fast 16.00
and so....

in otherwords put the header of each dog race into a column field.
I can do it excel with about 2000 lines of if statements but can i do

it
in
access easier as i need to automate it as i have todo thousands of

them.








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
Would Like to Automate Batch File Creation and Text FIle Import socrtwo Excel Discussion (Misc queries) 2 August 18th 06 03:54 PM
automate importing text files? sinnetBS Excel Discussion (Misc queries) 0 June 22nd 06 11:34 PM
*difficult* importing slection from a txt file to new column Trogent Excel Programming 2 July 19th 05 04:22 AM
importing text file, removing data and outputting new text file Pal Excel Programming 8 February 27th 04 08:32 PM
messy text file-- how to automate import? new_user Excel Programming 3 September 16th 03 07:57 PM


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