Problem reading delimited file

MartinS

Active Member
Joined
Jun 17, 2003
Messages
487
Office Version
  1. 365
Platform
  1. Windows
Right, here's the deal.
As part of an application, i have to intereract with another application's data, so therefore I cannot change the layout of this data.
Basically, each month, a new month is added to a 'table' (in a text file) which has 13 delimited columns (a year and 12 months) by, say, for example 10 rows, i.e.

1994,100.1,100.2,100.3,100.4,100.5,100.6,100.7,100.8,100.9,100.0,99.9,99.8
1995,88.1,88.2,88.3,88.4,88.5,88.6,88.7,88.8,88.9,88.0,87.9,87.8
...
...
2003,77.1,77.2,77.3,77.4,77.5,77.6,77.7,77.8,77.9,77.0,76.9,76.8

The idea is the user enters a date into a userform, that date is then passed to my code below and this returns the figure for the year and month, or if not yet available, the latest available figure. The problem I'm having is where the month required is 01/04 but the last available yield is 12/03. It's probably really straightforward to change, but I just can't get my head around what needs to change. So with the above data, if the date "31/01/2004" is passed to the procedure, it would return 76.8 (the latest available figure) (the same would apply for any date in the future), yet if "30/06/2003" was passed, then it would return 77.6.
Here's my code:
Code:
Sub ReadNAEIndices(DateToLookFor As String)
NAELogFile="C:\TEMP\AVEARN.DAT"
Dim FileNo As Integer
Dim LastAvailableValue As Double
FileNo = FreeFile()             
    Open NAELogFile For Input Access Read Shared As #FileNo
        Do                      
            On Error Resume Next
                For IndCounter = 1 To 12 Step 1
                    IndValue(IndCounter) = 0
                Next IndCounter
                    Input #FileNo, IndDate, IndValue(1), IndValue(2), _
                        IndValue(3), IndValue(4), IndValue(5), IndValue(6), _
                        IndValue(7), IndValue(8), IndValue(9), IndValue(10), _
                        IndValue(11), IndValue(12)
                            If EOF(FileNo) Then
                                For IndCounter = 1 To 12 Step 1
                                    If CDbl(IndValue(IndCounter)) = 0 Then
                                        LastAvailableValue = IndValue(IndCounter - 1)
                                            Exit For
                                    End If
                                Next IndCounter
                                    If CInt(IndDate) <= Year(DateToLookFor) Then _
                                        IndValue(Month(DateToLookFor)) = LastAvailableValue
                                            Exit Do
                            End If
            On Error GoTo 0
        Loop Until CInt(IndDate) = Year(DateToLookFor)
    Close #FileNo
End Sub
If you would like the actual file I'm trying to read then please email me and I will send it to you, but hope my example above should be sufficient.
If I have omitted any required info, please let me know.
Regards, and thanks in advance
Martin
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top