JoinQuote2 – A Join variant that works with 2-dimensional arrays and quoted strings

' Join variant that works with' bi-dimensional arrays of any type' and that encloses string values between quotes'' ARR is the 2-dimensional array whose element must be joined' ROWSEPARATOR is the separator for rows (default is CRLF)' COLSEPARATOR is the separator fol columns (default is comma)' QUOTED is the character used to quote string values'     use a two-char string (eg "{}") if the openining'     and closing quote chars are different'     use a null string to suppress quoting featureFunction JoinQuoted2(arr As Variant, Optional ByVal RowSeparator As String = _    vbCrLf, Optional ByVal ColSeparator As String = ",", _    Optional ByVal Quotes As String = """") As String    Dim res As String    Dim r As Long    Dim c As Long        For r = LBound(arr) To UBound(arr)        For c = LBound(arr, 2) To UBound(arr, 2)            If VarType(arr(r, c)) <> vbString Then                res = res & arr(r, c)            Else                ' the following code works correctly if                ' LEN(Quotes) is 0,1,2                res = res & Left$(Quotes, 1) & arr(r, c) & Right$(Quotes, 1)            End If            If c < UBound(arr, 2) Then res = res & ColSeparator        Next        If r < UBound(arr) Then res = res & RowSeparator    Next        JoinQuoted2 = resEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: