Cell Range export to Text File Issue

scwisely

New Member
Joined
Jun 21, 2019
Messages
22
I have the below code to select a range of cells and export it to a text file; however, the cells I am selecting contain formulas and after I export and open the text file I only get "#REF..... I think I need this to maybe paste the values instead? Please help...

Code:
Sub ExportRangetoFile()'Update 20130913
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "ISM Export to Text"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
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:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I tried out a simple example, and it worked for me.
What program are you using to view your resulting text file?
Are there any errors in the original Excel file?
What do these formulas look like?
 
Upvote 0
Thanks Joe4! No errors when running the script and I open it using Notepad. Here's what I get when I select a couple of rows and cells. The first cells have just text (works good) ; however the remaining cells that have data validation or formulas , just show #REF !

Example:
Workflow Action Name #REF ! #REF ! #REF ! #REF ! #REF ! #REF !
Action Definition #REF ! #REF ! #REF ! #REF ! #REF ! #REF !

Thanks so much for taking a look - I'm puzzled
 
Upvote 0
Can you post what some of those formulas actually are?
 
Upvote 0
Thanks again Joe! The formulas in the cells are as follows:

Row 14 Columns E:Z =$E$4&" "&E13
Row 15 Columns E:Z =VLOOKUP(E13,Actions!$A:$E,2,FALSE)

I appreciate you looking at this are your time
 
Upvote 0
OK, so are you saying that you have this formula in cell E14:
Code:
[COLOR=#333333]=$E$4&" "&E13[/COLOR]
and this is one of the formulas returning errors?
Or is it just the VLOOKUP formulas returning errors?
Can you tell me exactly what you have in cells E4 and E13?

I am trying to recreate your exact scenario, so I can see if I can produce the same results you are seeing.
 
Upvote 0
Hey Joe,
The formulas work perfectly and no errors. In cell E4 I have the text "Clinic" in cell E13 "Patient Enters Room" so that the result would be "Clinic Patient Enters Room" and I need that result to be exported to my txt file.

THANKS A MILLION for sticking with me on this :)
 
Upvote 0
Also, I'd be happy to share the file with you too, if that would help - I'm at a total loss as to why this isn't working - THANK YOU!!!
 
Upvote 0
If you can upload the file to a file sharing site, and provide a link to it, I can probably take a look at it tonight when I am at home.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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
Back
Top