Question : Excel - Trying to move the contents of 2 columns into 1 cell with some formatting.

I have an excel sheet with 3 columns in it: SKU#, LOT#, and quantity.  In the existing sheet I have multiple lines for each SKU# because each SKU has multiple Lots.

Unfortunately my inventory software needs to be formatted differently.  It needs 3 columns SKU, Lot numbers & total Quantity. I need to enter the Lots in the format "LOT1(QTY),LOT2(QTY)" and the total quantity column would be the quantity of all lots added together. (I've attached examples of the two files, probably clearer than my explanation.

I'm hoping to find a way to use a script for formula to make this easier, some of this SKUs have a hundred Lot numbers, so re-typing these into the necessary format is a lot of work, and asking for typos. If anyone has an idea I'd be greatful.

Thanks,
Attachments:
 
Existing Inventory File
 
 
Format Necessary for Import
 

Answer : Excel - Trying to move the contents of 2 columns into 1 cell with some formatting.

Here is one approach, results on sheet2.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
Sub x()

Dim oDic As Object, sNames() As String, vInput(), i As Long, n As Long

vInput = Sheet1.Range("A1", Sheet1.Range("C" & Rows.Count).End(xlUp)).Value
ReDim sNames(1 To UBound(vInput, 1), 1 To 3)
Set oDic = CreateObject("Scripting.Dictionary")

With oDic
    For i = 1 To UBound(vInput, 1)
        If Not .Exists(vInput(i, 1)) Then
            n = n + 1
            sNames(n, 1) = vInput(i, 1)
            sNames(n, 2) = vInput(i, 2) & "(" & vInput(i, 3) & ")"
            sNames(n, 3) = vInput(i, 3)
            .Add vInput(i, 1), n
        ElseIf .Exists(vInput(i, 1)) Then
            sNames(.Item(vInput(i, 1)), 2) = sNames(.Item(vInput(i, 1)), 2) & ", " & vInput(i, 2) & "(" & vInput(i, 3) & ")"
            sNames(.Item(vInput(i, 1)), 3) = sNames(.Item(vInput(i, 1)), 3) + vInput(i, 3)
        End If
    Next i
End With

Sheet2.Range("A1").Resize(n, 3) = sNames

End Sub
Random Solutions  
 
programming4us programming4us