Merge cells from different rows depending on certain criteria

gemf89

New Member
Joined
Aug 1, 2018
Messages
1
Hello. I have been looking for an answer but obviously it is hard to find a case exactly like mine and I dont have the technical nous to change anything without screwing it up. If you can help I will be very grateful.

I get an auto-generated spreadsheet from a software. This is a sales software where I can find many orders with different products and there is row for every product even in the same order. I need to merge those rows into only one for every order.

Original spreadsheet
ClientOrder No. ProductPrice
Robert001Apples2
Robert001Oranges1
Max002Apples2
Max002Oranges1
Max003Apples2

<tbody>
</tbody>











What I need is to automatically detect every single order No. and merge those rows into one. Like these:

ClientOrder No. ProductPrice
Robert001Apples-Oranges2-1
Max002Apples-Oranges2-1
Max003Apples2

<tbody>
</tbody>








thank you!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
See next code
Code:
Option Explicit


Sub MergeCells()
Const FR = 2
Dim DataDic   As Object
Set DataDic = CreateObject("Scripting.Dictionary")
Dim Rg As Range
Dim I  As Integer
Dim AAA, BBB
    Columns(4).Cells.NumberFormat = "@"
    For I = FR To Cells(Rows.Count, 1).End(3).Row
        With DataDic
            If (.exists(Cells(I, 1) & Cells(I, 2))) Then
                Cells(.Item(Cells(I, 1) & Cells(I, 2)), 3) = Cells(.Item(Cells(I, 1) & Cells(I, 2)), 3) & " - " & Cells(I, 3)
                Cells(.Item(Cells(I, 1) & Cells(I, 2)), 4) = Cells(.Item(Cells(I, 1) & Cells(I, 2)), 4) & " - " & Cells(I, 4)
                Cells(I, 1) = ""
            Else
                .Item(Cells(I, 1) & Cells(I, 2)) = I
            End If
            AAA = .keys: BBB = .items
        End With
    Next
    Columns(1).Cells.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    MsgBox ("Job Done")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,541
Messages
6,125,413
Members
449,223
Latest member
Narrian

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top