将一列值转换成一行

所以我有这样的数据:

AB sku custom_option_row_sku AGR370A AGR370A-3 AGR370A-4 AGR370A-5 AGR370A-6 AGR370A-8 AGR370A-9 AGR370A-10 AGR370A-210 AGR370A-212 AGR370B AGR370B-3 AGR370B-4 ... 

我需要拿B列,把它变成一行,以便它仍然匹配列A中的值

这将最终结果如下:

  AB sku custom_option_row_sku AGR370A AGR370A-3, AGR370A-4, AGR370A-5, etc. 

这是可能的内置function,或者我需要VBA吗? 提前致谢。

我只是用你给我的例子来做这个代码。 如果您有任何问题,请告诉我,但是对我有用。 一定要做一个备份副本以防万一。

  Sub resort() Dim thesheet As Worksheet Set thesheet = Sheets("Sheet1") Dim lastrow As Long Dim x As Long Dim newRow As Long Dim colA As String Dim deleterRow As Long lastrow = thesheet.Range("B" & Rows.Count).End(xlUp).Row With thesheet newRow = 0 For x = 1 To lastrow colA = .Cells(x, 1).Value If colA <> "" Then colA = .Cells(x, 1).Value newRow = x Else .Cells(newRow, 2).Value = .Cells(newRow, 2).Value & ", " & .Cells(x, 2).Value End If Next deleterRow = 1 For x = 1 To lastrow colA = .Cells(deleterRow, 1).Value If colA = "" Then .Rows(deleterRow).Delete Else deleterRow = deleterRow + 1 End If Next End With End Sub 

如果没有那么多的信息,你不一定需要VBA。 从列中复制所需的数据,转到要粘贴的行,右键单击 – >select性粘贴 – >移调。 图标看起来像这样: 在这里输入图像说明