M
Mohan
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
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