Consulting

Results 1 to 2 of 2

Thread: concatenate variable values

  1. #1

    concatenate variable values

    Hi,

    I hope someone can help me with this vba question.

    I want to concatenate some values, but these values are variable. Sometimes the're 3 values and sometimes the're 5 or more values.

    In cell A4 is a value and behind that the're 3 values and those 3 values I need to concatenate.
    The next cell is A7 and behind that the're 5 values and those 5 values I need to concatenate.

    I tried to count the empty cells between the values in column A and use this as variant for the concatenate formule. But it didn't worked.

    I've attached a example so you maybe understand my question. example concatenate.xlsx

    Thanks,
    Peter

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Public Sub ConcatenateValues()
    Dim values As String
    Dim lastrow As Long
    Dim i As Long
    
        With ActiveSheet
        
            lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row
            values = vbNullString
            For i = lastrow To 1 Step -1
            
                values = Cells(i, "C").Value & "," & values
                If .Cells(i, "A").Value <> vbNullString Then
                
                    Cells(i, "E").Value = Right$(values, Len(values) - 1)
                    values = vbNullString
                End If
            Next i
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •