Reading data in and out of text files

sarithgada86

New Member
Joined
Jul 25, 2011
Messages
4
Hello,

I am trying to create a small database that reads data into a text file. I've used names ranges to help me do that. It reads data out into the text file, stating the named range and then the data in that range (all 1 column wide).

This is the code I have been using:

Sub RangeToText()

Set fs = CreateObject("Scripting.FileSystemObject")
Set x = fs.CreateTextFile(Range("filepath") & Range("studentname") & " " & Range("Basegroup") & ".txt")

For a = 1 To Range("rangeformacro").Rows.Count
b = Range("rangeformacro").Rows(a)

x.writeline b

For c = 1 To Range(b).Rows.Count

x.writeline (Range(b).Rows(c))

Next c


Next a

End Sub

As a result my text file looks like this:

StudentName
Joe Bloggs
BaseGroup
7H
College
Holmes College


How can I use this format to read back into excel after selecting the file I want?

Thanks,

Sarith
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

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