Consulting

Results 1 to 2 of 2

Thread: Merge and Combine data

  1. #1
    VBAX Mentor
    Joined
    Feb 2012
    Posts
    406
    Location

    Question Merge and Combine data

    Hello ,

    i have 2 sheet in sheet1 I have 4 column like the below image that you see A To D and column A have duplicate data but other column Have Different data .

    I need to merge all column that their column A is same and give me the result like second image on sheet2

    Please help me on this subject



    I need this result in sheet2 , that mean data on column C1 added to first of data on column B1 and add () and dara on column D1 added between ().

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    didn't notice it was solved! Anyway:
    Sub blah()
    Set StartCll = Sheets("Sheet1").Range("A1")
    Do Until IsEmpty(StartCll)
      ofst = 0
      Do Until StartCll.Value <> StartCll.Offset(ofst).Value
        ofst = ofst + 1
      Loop
      Set EndCll = StartCll.Offset(ofst - 1)
      Set block = Range(StartCll, EndCll)
      Set Destn = Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1)
      StartCll.Copy Destn
      ReDim myStrings(1 To block.Rows.Count)
      i = 1
      For Each celle In block.Cells
        myStrings(i) = Join(Array(celle.Offset(, 2).Value, celle.Offset(, 1).Value, "(" & celle.Offset(, 3).Value & ")"), " ")
        i = i + 1
      Next celle
      Destn.Offset(, 1) = Join(myStrings, ", ")
      Set StartCll = EndCll.Offset(1)
    Loop
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

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