Exporting to another file format

rcb007

Board Regular
Joined
Nov 12, 2020
Messages
64
Office Version
  1. 365
Platform
  1. Windows
I have the following vba code that would take a column and export it to a txt. However when it runs, the formulas in the exported txt show as #REF!

I did a quick macro manually doing what I wanted and noticed the Paste was not a PasteSpecial. I added this and it still did not work, unless I have it in wrong.

thank you!

VBA Code:
Sub EXPORT()

Sheets("Sheet2").Cells(Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Row - 22, "A").Resize(23).Value = Sheets("Sheet3").Range("W19:W43").Value
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
Set WorkRng = Sheets("Sheet2").Range("AA1:AA24635")
Application.ScreenUpdating = True
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
'wb.Wroksheets(1).Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
 :=False, Transpose:=False
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 = False

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,140
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
I added this and it still did not work, unless I have it in wrong.

VBA Code:
wb.Wroksheets(1).Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
You have spelt WorkSheets wrong. Try...
VBA Code:
wb.WorkSheets(1).Cells(1,1).PasteSpecial xlValues
Change Paste destination to suit (top left cell of the range).
 

rcb007

Board Regular
Joined
Nov 12, 2020
Messages
64
Office Version
  1. 365
Platform
  1. Windows
Great!!! it worked and thanks for the eyes!
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,140
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You're welcome
 

Forum statistics

Threads
1,136,196
Messages
5,674,372
Members
419,505
Latest member
tismail

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top