I have a sheet that has some columns and rows.
I want to save a separate text file on the desktop with one click from the range of each column.
I have a code but it works incompletely
This code only stores the columns without the range in one file, but I need the range of each column to be stored in a separate text file.
Please Help
Thank you
My Code :
I want to save a separate text file on the desktop with one click from the range of each column.
I have a code but it works incompletely
This code only stores the columns without the range in one file, but I need the range of each column to be stored in a separate text file.
Please Help
Thank you
My Code :
VBA Code:
Sub AnExample()
If ExportRange(Intersect(ActiveSheet.UsedRange, Columns("B")), "GetDesktop()" & _
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