mdrollins83
New Member
- Joined
- Nov 19, 2017
- Messages
- 4
I am attempting to write to a txt file in excel from two separate ranges in 2 different sheets. Below is the code that works, but it leaves a carriage return at the end of the txt file that I cannot have when importing into our software. Could anyone be able to help a VBA beginner out with this?
Code:
Sub WriteToTextFile()
Dim fs As New FileSystemObject
Dim rng1 As Range
Dim ws As Worksheet
Set ws = Sheets("1099 Import Header")
Set txtfile = fs.CreateTextFile(ThisWorkbook.Path & "\1099 Import.txt")
Set rng1 = ws.Range("List_1099H")
For Each r In rng1.Cells
For Each cel In r
txtfile.Write cel.Value
Next
txtfile.Write vbNewLine
Next
Dim rng2 As Range
Dim wr As Worksheet
Set wr = Sheets("1099 Import Detail")
Set rng2 = wr.Range("List_1099D")
For Each r In rng2.Cells
For Each cel In r
txtfile.Write cel.Value
Next
txtfile.Write vbNewLine
Next
End Sub