I have a procedure that exports a spreadsheet to a text file. It puts a carriage return after each row by default and the last record causes a blank row in the text (flat) file. Is there away to remove the last carriage return? Here is the code that I've used.
Thanks
lhuffst
Code:
'
' Exportit Macro
' Macro recorded 6/18/2008 by lhuffst
Dim wbNew As Workbook
Set wbNew = Workbooks.Add
'
Dim NewDate As String
ThisWorkbook.Sheets.Add after:=Sheet1
lrow = Sheet1.UsedRange.Rows.Count
Set r1 = Sheet1.Range(Cells(2, 1), Cells(lrow, 3))
Set r1 = Application.Union(r1, Range(Cells(2, 7), Cells(lrow, 9)))
Set r2 = Sheet1.Range(Cells(4, "K"), Cells(lrow, "K"))
'Concatanate the fields
Dim counter
'columns are: 1-200ft sheet, 2-Work Order #, 3-PageGrid, 7-Date, 8-Rpt By, 9-condition Code
For counter = 2 To lrow
NewDate = Format(Cells(counter, 7).Value, "mmddyy") 'removes the / on dates
Cells(counter, "K").Value = _
Cells(counter, 1).Value & _
Cells(counter, 2).Value & _
Cells(counter, 3).Value & _
NewDate & _
Cells(counter, 8).Value & _
Cells(counter, 9).Value
Debug.Print Mid(Cells(counter, 7).Value, 1, 2) & Mid(Cells(counter, 7).Value, 4, 2) & _
Mid(Cells(counter, 7).Value, 7, 2)
Next counter
'copy to new sheet
'r1.Copy (Sheets(Sheets.Count).[a1])
'r2.Copy (Sheets(Sheets.Count).[a1])
r2.Copy wbNew.Sheets(1).[a1]
'save the new sheet
'Sheets(Sheets.Count).SaveAs Filename:="D:\My Data\FireHydrant Database\MainframeSide\testitNew.txt", FileFormat:=xlTextWindows
wbNew.Sheets(1).SaveAs Filename:="D:\My Data\FireHydrant Database\MainframeSide\testitToday.txt", FileFormat:=xlTextWindows
wbNew.Close
'delete the temporary sheet
Sheets(Sheets.Count).Delete
Thanks
lhuffst