简体   繁体   中英

Turning a column of values into a row

So I have data like this:

 A             B
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
        ...

I need to take column B and turn it into a row so that it still matches the value in column A.

It would ideally end up like:

 A                 B
sku      custom_option_row_sku
AGR370A  AGR370A-3, AGR370A-4, AGR370A-5, etc.

Is this possible with a built in feature or would I need VBA for this? Thanks in advance.

I just did it with this code using the example you gave me. If you have any issues let me know, but it worked for me. Be sure to make a backup copy just in case.

 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

If it's not that much information, you don't necessarily need VBA. Just copy the data you want from the column, go to the row you want to paste in, right click -> Paste Special -> Transpose. The icon looks like this: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM