I found a VBA code that almost fits my requirements to export data to a CSV file. I am having problems with the delimiter function.
I have the following function:
Function DelimitRange(ByVal XLArray As Variant) As String
Const delimiter As String = ","
Const lineFeed As String = vbCrLf
Const removeExisitingDelimiter As Boolean = True
Dim rowCount As Long
Dim colCount As Long
Dim tempString As String
For rowCount = LBound(XLArray, 1) To UBound(XLArray, 1)
For colCount = LBound(XLArray, 2) To UBound(XLArray, 2)
If removeExisitingDelimiter Then
tempString = tempString & Replace(XLArray(rowCount, colCount), delimiter, vbNullString)
Else
tempString = tempString & XLArray(rowCount, colCount)
End If
'Don't add delimiter to column end
If colCount < UBound(XLArray, 2) Then tempString = tempString & delimiter
Next colCount
'Add linefeed
If rowCount < UBound(XLArray, 1) Then tempString = tempString & lineFeed
Next rowCount
DelimitRange = tempString
End Function
This code is generating me something like that:
a,,,
d,,z,
uo,,,
u,,c,
h,,,
I need this function to generate the line skipping extra commas when there is no more characters to display at the end of each line.
I need this function to give me the following output (using the same data as the example given before:
a
d,,z
uo
u,,c
h
Thanks in advance for your help.