Consulting

Results 1 to 3 of 3

Thread: Excel macro, combine cells based on same merged row i different column

  1. #1
    VBAX Regular
    Joined
    Mar 2014
    Posts
    7
    Location

    Question Excel macro, combine cells based on same merged row i different column

    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.Combinecell.xlsx

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    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

  3. #3
    VBAX Regular
    Joined
    Mar 2014
    Posts
    7
    Location
    Thanks

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


Posting Permissions

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