Answer the question
In order to leave comments, you need to log in
How to merge excel cells by condition?
Hello.
In the first column of excel, the values corresponding to them in the second, but in different lines:
You need to combine all "a" in a cell opposite 1, all b opposite 2, etc., while preserving line wrapping:
Naturally, there are thousands of records.
Tell me, please, how to do it?
Answer the question
In order to leave comments, you need to log in
I threw it without any special beauty :)
Of the minuses:
- between the values after processing there are empty lines equal to the number of elements - 1 in the second column (respectively concatenated values); empty lines in excel should not be a problem;
- the initial initialization is tied to the location of the elements.
Don't forget to extend the Range() for the loop.
Sub concat()
txt = Range("B1").Text
Range("A1").Select
Set hCell = ActiveCell
For Each cell In Range("A1:A20")
If cell.Value <> "" Or cell.Offset(0, 1).Value = "" Then
hCell.Offset(0, 1).Value = txt
cell.Select
Set hCell = ActiveCell
txt = ""
End If
If cell.Offset(0, 1).Value = "" Then
Exit Sub
End If
txt = txt + vbCrLf + cell.Offset(0, 1).Text
' Очистка ячейки
cell.Offset(0, 1).Value = ""
Next
End Sub
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question