PDA

View Full Version : [SOLVED] Excel macro, combine cells based on same merged row i different column



AndersW
06-11-2019, 01:39 PM
Hi,
I have a excel sheet with about 4000 rows. In column A there is an ID for the text that is in Column B. the text that is in column B is a large amount of text for each cell in the original sheet. And there can be anything from 1 to 15 cells in Column B that share the same ID in Column A. In Column A the ID is only typed once since the cell there are merged.
So does any of you have a neat macro that could combine the context in Column B cells into one cell in Column C next to the first cells from B. The combined text in column C should start at a new line inside (char 10) inside the combined cell when picking text from the different cells in Column B

See attached excel workbook where I have given example of the setup and what I hope the outcome of the macro could look like.24369

大灰狼1976
06-11-2019, 07:02 PM
Hi AndersW!
Something like below:

Sub test()
Dim i&, s$, r&, rw&
rw = [b65536].End(3).Row
For i = 2 To rw
If Cells(i, 1) <> "" Then
If i > 2 Then
Cells(r, 4) = Mid(s, 2)
s = ""
End If
r = i
End If
s = s & Chr(10) & Cells(i, 2)
Next i
Cells(r, 4) = Mid(s, 2)
End Sub

AndersW
06-12-2019, 12:39 AM
Thanks

With a little formating on my original workbook this worked perfectly.
:clap: