What I'm trying to do is write out text files based on groups of rows. Each text file is named after the value of a cell in column A and contains the values in column B. The groups are also seperated by the column A.
For example:
<tbody>
</tbody>
So "Filename1.txt" would contain the 3 rows of "text" and "Filename2.txt" would contain the 4 rows of "text2" etc...
I have pieced together some code from help and research around the web, but it only works when using a fixed number of rows.
Here is what I have:
This works for fixed 4 line groups...I need it to work on varible number of rows.
Any help on this would be a huge time saver. Thanks!
For example:
A | B |
Filename1 | text |
text | |
text | |
Filename2 | text2 |
text2 | |
text2 | |
text2 |
<tbody>
</tbody>
So "Filename1.txt" would contain the 3 rows of "text" and "Filename2.txt" would contain the 4 rows of "text2" etc...
I have pieced together some code from help and research around the web, but it only works when using a fixed number of rows.
Here is what I have:
Code:
Sub export_multiple_line_files()
'assumes current sheet needs outputting
'assumes four lines per file -- filenames in column a; contents in column b
file_path = "c:\"
r = 1
Do While Not IsEmpty(Range("a" & r))
cur_file = Range("a" & r).Value & ".txt"
Open file_path & "\" & cur_file For Output As #1
For i = 0 To 3
Print #1, Range("b" & r + i).Value
Next i
Close #1
r = r + 4
Loop
End Sub
This works for fixed 4 line groups...I need it to work on varible number of rows.
Any help on this would be a huge time saver. Thanks!