컴퓨터/엑셀

excel vba textjoin 함수 구현

풍경소리^^ 2025. 10. 28. 10:19
Function TEXTJOIN_VBA(Delimiter As String, IgnoreEmpty As Boolean, ParamArray TextRanges() As Variant) As String
    Dim Item As Variant
    Dim Cell As Range
    Dim Result As String
    
    On Error Resume Next
    
    For Each Item In TextRanges
        ' 개별 인자 처리
        If IsObject(Item) Then
            ' Range가 전달된 경우
            For Each Cell In Item
                If Not (IgnoreEmpty And Trim(Cell.Value) = "") Then
                    Result = Result & Delimiter & Cell.Value
                End If
            Next Cell
        Else
            ' 단일 값인 경우
            If Not (IgnoreEmpty And Trim(Item) = "") Then
                Result = Result & Delimiter & Item
            End If
        End If
    Next Item
    
    ' 맨 앞 구분자 제거
    If Len(Result) > 0 Then
        Result = Mid(Result, Len(Delimiter) + 1)
    End If
    
    TEXTJOIN_VBA = Result
End Function

 

아 리 랑 =TEXTJOIN_VBA(", ",FALSE,A1:C1)
아, 리, 랑


아      랑 =TEXTJOIN_VBA(", ",FALSE,A1:C1)
아, , 랑

 

FALSE 공백무시 안함