Originally Posted by
lucas
Great solution Matt. Glad you came along to help.
I don't usually look at questions that already have some replies to it, but for some reason I clicked on this one.
The only downfall to this might be if some of the columns being exported contain specific numberformats, as this just takes the underlying values. Of course it can be changed if need be.
You could also have a function for this:
Sub AnExample()
If ExportRange(Intersect(ActiveSheet.UsedRange, Columns("C:IV")), "C:\" & _
Format(Date, "ddmmyy") & ".txt", Chr$(9)) Then MsgBox "File Saved"
End Sub
Function ExportRange(ByVal TheRange As Range, ByVal TheFile As String, Optional ByVal _
vDelimiter As String = ",") As Boolean
Dim URArr(), i As Long, j As Long, vFF As Long, ExpArr() As String
On Error GoTo QuitFunc
URArr = TheRange.Value
ReDim ExpArr(1 To UBound(URArr, 1))
For i = 1 To UBound(URArr, 1)
For j = 1 To UBound(URArr, 2) - 1
ExpArr(i) = ExpArr(i) & URArr(i, j) & vDelimiter
Next 'j
ExpArr(i) = ExpArr(i) & URArr(i, UBound(URArr, 2))
Next 'i
vFF = FreeFile
Open TheFile For Output As #vFF
For i = 1 To UBound(ExpArr)
Print #vFF, ExpArr(i)
Next 'i
Close #vFF
ExportRange = True
Exit Function
QuitFunc:
End Function