I have a macro which exports XLS to TXT and it works fine, except that the resulting TXT contains not only the useful data, but also empty lines below this data.
I may be mistaken, but looks like empty Excel cells are exported too. Is there a way to improve my code to export only those cells which have data?
Here's the link to the XLS file to be exported.
Here's the link to the resulting TXT file. Use keyboard arrow keys to see empty TABs below line #1, which contains useful data.
And here's the code:
Option Explicit
Sub Export_to_TXT_UTF16()
Dim saveas_filename As Variant
saveas_filename = Application.GetSaveAsFilename(FileFilter:="Unicode Text (*.txt), *.txt", Title:="SaveAs")
If saveas_filename = False Then
Exit Sub
End If
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
ActiveSheet.Copy
With ActiveSheet.UsedRange
.Value = .Value
End With
Rows(1).Delete 'DELETE ROW #1
Columns("C:G").Delete 'DELETE COLUMNS C-G
ActiveWorkbook.SaveAs Filename:=saveas_filename, FileFormat:=xlUnicodeText
ActiveWorkbook.Close SaveChanges:=False
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
MsgBox "Your data has been exported!", vbExclamation, "Sheet Exported"
End Sub