I recently received excellent guidance here for obtaining data from a text file and writing it to a worksheet.
I thought I'd be clever and try to write my own code to now do it in reverse - to write data back to a .txt file - using the coding that I thought I'd learned.
Not so! All I've managed to do is completely delete everything that was previously in the .txt file! I'm guessing I missed adding something to actually write the data.
What I'm trying to do is copy Range C3:C102 from the open worksheet to an existing text file. The data is to be written as a single column and can overwrite the existing data.
My non-functional coding is:
- Sub WriteM400AD()
- Dim strLine As String
- Dim strFile As String
- Dim iRow As Integer
- Dim iColumn As Integer
- strFile = "F:\SM Lists\M400AD.txt"
- iRow = 2
- iColumn = 3
- Open strFile For Output As #1
- Do While Not EOF(1)
- iRow = iRow + 1
- Line Input #1, strLine
- Cells(iRow, iColumn).Value = strLine
- Close #1
- End Sub
Help on sorting out my mess would be much appreciated.