PDA

View Full Version : [SOLVED:] concatenate variable values



9!GR@BzyQ37b
05-01-2020, 03:03 AM
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. 26525

Thanks,
Peter

Bob Phillips
05-01-2020, 03:16 AM
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