Turn Excel range into VBA string

前端 未结 7 1817
野性不改
野性不改 2020-11-30 11:51

I would like to turn values in given range into VBA string where original cell values are separated by any chosen column delimiter and row delimiter. Delimiters could be one

7条回答
  •  渐次进展
    2020-11-30 12:25

    How about this?:

    Sub Concatenate()
    Dim Cel As Range, Rng As Range
    Dim sString As String, r As Long, c As Long, r2 As Long
    
    Set Rng = Selection
    r = Selection.Row
    c = Selection.Column
    r2 = Selection.Row
    For Each Cel In Rng
        r = Cel.Row
        If sString = "" Then
            sString = Cel.Value
            Else
                If r <> r2 Then sString = sString & "@" & Cel.Value
                If r = r2 Then sString = sString & "," & Cel.Value
        End If
        r2 = Cel.Row
    Next
    
    sString = sString & "@"
    Debug.Print sString
    
    End Sub
    

提交回复
热议问题