我發現了一個幾乎符合我的要求將數據導出到CSV文件的VBA代碼。我遇到了分隔符函數的問題。設置分隔符以生成導出
我有以下功能:
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
此代碼生成我類似的東西:
a,,,
d,,z,
uo,,,
u,,c,
h,,,
我需要這個功能來生成跳行額外的逗號時,有沒有更多的字符在每行的結尾顯示。
我需要這個功能給我下面的輸出(使用相同的數據作爲例子給出前:提前
a
d,,z
uo
u,,c
h
感謝您的幫助
和數組是什麼? – 2013-07-22 14:35:03
'rngArray = Excel.Worksheets(「MySheet」)。Range(「A3:D」&lineSize).Value' –