Systematically reading from txt or csv file

wizard68

New Member
Joined
Sep 7, 2006
Messages
3
G'day all,

I have 5min forex data in txt and csv format that I want to run some tests on in excel.

I don't know how this is going to evolve, but for the moment I want to be able to read in one line of data at a time, do whatever calculations I desire, then read the next line in, then the next, etc. I want this process to be manually instigated, ie. click a button for next line of data.

Any ideas on this data reading process?

Cheers,
Andrew.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Andrew

Take a look at the File I/O methods available via VBA.

You'll find plenty of information on them in the Help files.
 
Upvote 0
Andrew

Take a look at the File I/O methods available via VBA.

You'll find plenty of information on them in the Help files.

I know I'm new to this, but under the help section of VBA I can't get help on "File I/O". I can get help on Opening files and importing files, but that's not exactly what I'm looking for.

Any pointers to sites where I could read up on this is greatly appreciated.

Cheers,
Andrew.
 
Upvote 0
Thanks for that code. I've managed to change it slightly to read every line until eof but it does it in a loop all at once. I want to click the button, read first line, click button read second line, click, next line...etc etc..

I know it has to do with the Do..Loop but I can't seem to be able to get it to wait for a click before grabbing the next line..

Any help would be much appreciated...

' *** Change to suit ***
Dim LineNo As Integer
Dim FileName As String
Dim FileNum As Integer
Dim r As Long
Dim wb As Workbook
Dim Data As String
'' *** Change path and file name to suit ***
FileName = "C:\Temp\M1_EURUSD_1.txt"
FileNum = FreeFile
Open FileName For Input As #FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, Data
'' If r = LineNo Then
ActiveSheet.Cells(1, 1) = Data
'' Exit Do
'' End If
'' r = r + 1
Loop
Close #FileNum

Cheers,
Andrew.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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