0

我可以合并具有相同 SKU 的单元格并使用下面的代码删除该行,但是我不知道如何将 sku + qty 也组合在同一行中。

id     sku   Qty Total Qty  Weight  Address Zip     etc...
576996  A     1      7       2.6            
576996  B     1      7       2.6            
576996  C     2      7       2.6            
576996  D     3      7       2.6            

Current code sku              Qty               
576996  A, B, C, D     1, 1, 2, 3     7  2.6



Desired                            Qty          
576996  A (1),B(1),C(2),D(3)    1, 1, 2, 3     7    2.6 


Dim sh As Worksheet, lr As Long
Set sh = Sheets(1) 'Edit sheet name
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 3 Step -1
    With sh
        If .Cells(i, 1) = .Cells(i - 1, 1) Then
            If .Cells(i - 1, 2).Value <> .Cells(i, 2).Value Then
                .Cells(i - 1, 2) = .Cells(i - 1, 2).Value & ", " & .Cells(i, 2).Value
                .Cells(i - 1, 3) = .Cells(i - 1, 3).Value & ", " & .Cells(i, 3).Value
            End If
            Rows(i).Delete
        End If
    End With
Next
End Sub     
4

1 回答 1

1

只需延长设置 sku 的行

 .Cells(i - 1, 2) = .Cells(i - 1, 2).Value & ", " & _ 
     .Cells(i, 2).Value & " (" & .Cells(i, 3) & ")"
于 2013-09-28T18:36:19.520 回答