I'm looking to create a .txt file
for each value in column A
containing the corresponding values in columns B and C
Answer
The more I looked at this the more I found it to be a useful little macro. In order to keep it from processing blank rows (and locking up my Excel) I rewrote the code to only create a file while there is data available. Also, the use of print
rather than write
creates text without the quotations. Here is what I used to accomplish the same thing.
Sub CreateFile()
Do While Not IsEmpty(ActiveCell.Offset(0, 1))
MyFile = ActiveCell.Value & ".txt"
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum
'use Print when you want the string without quotation marks
Print #fnum, ActiveCell.Offset(0, 1) & " " & ActiveCell.Offset(0, 2)
Close #fnum
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Feel free to use and modify as you wish. Thanks for the great idea.
No comments:
Post a Comment