kwaku101
09-30-2008, 06:47 AM
Help, I'm trying to accomplish the following.
- Read data from cell A2 to C9.
- Write the data to a .txt document on my c drive.
So far the code below simply writes the second row of data 8x, I can't get it to loop through the rest of the rows. Please help if you can.
Thanks you
Sub writetext()
Dim outfile As String, Num As Integer, Code1 As String, Code2 As String
outfile = "c:\samplefile.txt"
Open outfile For Output As #1
Num = Worksheets("text file").Range("A2")
Code1 = Worksheets("text file").Range("A3")
Code2 = Worksheets("text file").Range("A4")
For x = 2 To 9
Write #1, Num, Code1, Code2
Next x
Close #1
End Sub
- Read data from cell A2 to C9.
- Write the data to a .txt document on my c drive.
So far the code below simply writes the second row of data 8x, I can't get it to loop through the rest of the rows. Please help if you can.
Thanks you
Sub writetext()
Dim outfile As String, Num As Integer, Code1 As String, Code2 As String
outfile = "c:\samplefile.txt"
Open outfile For Output As #1
Num = Worksheets("text file").Range("A2")
Code1 = Worksheets("text file").Range("A3")
Code2 = Worksheets("text file").Range("A4")
For x = 2 To 9
Write #1, Num, Code1, Code2
Next x
Close #1
End Sub