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
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