reading tab delimited text in variables....

ckmoied

Board Regular
Joined
Oct 13, 2002
Messages
154
Hi all,

I have some tab delimited text files, which I want to read using VBA codes.

In these files, the data is stored as follows:

Date Time Col1 Col2 Col3 ...........
01/01/99 18:10:00 25.5 26.3 27.9 ...........
01/02/02 15:18:00 14.5 25.3 18.5 ..........
. . . . .
. . . . .
. . . . .

Now reading the file as a whole is no problem, but I want to read these files in such a way that each colum is stored in separate variables.

For Instance

date_1= The values in the first column from rows 1 to 3
date_2= The values in the first column from rows 8 to 15
time_1= the values in the second column from rows 1 to 3
time_2= the values in the second column from rows 8 to 15
var_a1= the values in the third column from rows 1 to 3
var_a2= the values in the third column from rows 8 to 15
var_b1= the values in the fourth column from rows 1 to 3
var_b2= the values in the fourth column from rows 8 to 15
and so on

any coding help or reference would be appreciated??
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,659
Office Version
  1. 2016
  2. 2003 or older
Platform
  1. Windows
Hi ckmoied,
Declare variables as a variant type, and you can store the cell value as follows.
I think using cells property is easy to understand.

date_1= The values in the first column from rows 1 to 3

Cells(1, 1) stands for Cells(row 1, Column A)
Cells(3, 1) stands for Cells(row 3, Column A)

So the code would be

Code:
Dim date_1 As Variant
Dim date_2 As Variant
date_1 = Range(Cells(1, 1), Cells(3, 1)).Value
date_2 = Range(Cells(8, 1), Cells(15, 1)).Value

In this case, date_1 will be an 2-d array, you can get value from an array something like this.

Code:
Msgbox date_1(1,1)

date_1(1,1) has a value 01/01/99
date_1(2,1) has a value 01/02/02
date_1(3,1) ...

Please feel free to let me know if you have any further questions.
 
Upvote 0

ckmoied

Board Regular
Joined
Oct 13, 2002
Messages
154
Hi Colo,
Thanking for your support. I got your points on the solution, but I am sorry that I didn't explain my problem fully.

Your solution suggests the use of worksheet, but in fact I want to avoid the use of such worksheet, rather I want to read the data in local variables within visual basic code. Reading the text file and put it in worksheet is no problem.

In fact I am using VB6 and have developed a form where I have to show the dates, time and their respective data. After that I want to plot this data against time and date within the same form in a chart and in this whole process I want to avoid the use of worksheets.

Hope I explained this time.
 
Upvote 0

Forum statistics

Threads
1,195,849
Messages
6,011,955
Members
441,657
Latest member
Diupsy

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