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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
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.
 

wizard68

New Member
Joined
Sep 7, 2006
Messages
3
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.
 

wizard68

New Member
Joined
Sep 7, 2006
Messages
3
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.
 

Forum statistics

Threads
1,137,060
Messages
5,679,372
Members
419,824
Latest member
Mercy kiara

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
Top