LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Text import and transpose - pretty difficult

Hi
I have a text file (tabe delimitted) that gives tha cash flow of intial
investment. This looks like:
ValDate PoolNo CF_date CF_Amt
08/01/2007 12345 01/01/2007 100.00
08/01/2007 12345 02/01/2007 200.00
08/01/2007 12346 01/01/2007 100.00
08/01/2007 12346 02/01/2007 200.00
08/01/2007 12346 03/01/2007 250.00
08/01/2007 12346 04/01/2007 175.00

I am using the follwoing code to import:

Public Sub ImportTextFile(FName As String, Sep As String)

Dim RowNdx As Long
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer

Application.ScreenUpdating = False
'On Error GoTo EndMacro:

SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row

Open FName For Input Access Read As #1

While Not EOF(1)
Line Input #1, WholeLine
If Right(WholeLine, 1) < Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos = 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
Wend

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1

End Sub

This macro basically imports the file in the same row/column format. I want
to transpose the result in excel to look like :
Val Date Pool # CF_date1 CF_Amt1 CF_date2 CF_Amt2 ....
and so on for as many as cashflows given for the same pool no. (so its not a
set number of columns. If there are two rows in the text file for one pool
number (see sample pool no 12345 above) it should look like
Val Date Pool # CF_date1 CF_Amt1 CF_date2 CF_Amt2
08/01/2007 12345 01/01/2007 100.00 02/01/2007 200.00

If there are 10 rows for the same pool no, then I get the ValDate, Pool# and
20 columns for the CF_date (1 to 10) and CF_amt (1 to 10) - All together 22
columns

How can I modify this code to achive this? or any other suggestions...

total cash flows will not exceed 60 months. I dont have to worry about
exceeding the column limitation in Excel 2003.

Thanks
Mohan
 
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
Automate 'Difficult' importing text file MArk Excel Programming 4 May 29th 07 05:30 AM
Help: Import text transpose append to new worksheet javamom Excel Programming 4 April 20th 06 03:29 AM
difficult transpose? redb Excel Programming 6 October 4th 05 10:06 AM
Import and transpose tab seperated data from text file phillip harrison Excel Programming 0 July 22nd 03 05:44 PM
Import and transpose tab seperated data from text file phillip harrison Excel Programming 1 July 17th 03 03:48 PM


All times are GMT +1. The time now is 03:30 AM.

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

About Us

"It's about Microsoft Excel"