I am trying to use the below macro code to export a column within a sheet to a txt file. The final output shows " #REF! " within the text file. Not sure what I did.
Thanks for any help!
VBA Code:
Sub EXPORT()
'Update 20200131
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
'Set WorkRng = Sheets("Sheet1").Range("B1:B500")
Set WorkRng = Sheets("Sheet1").Range("B1:B" & Cells(Rows.Count, "J").End(xlUp).Row)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(FileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs Filename:=saveFile, FileFormat:=xlTextPrinter, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thanks for any help!