[英]Turning a column of values into a row
所以我有這樣的數據:
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
...
我需要將B列轉換為一行,以便它仍與A列中的值匹配。
理想情況下,它將最終像:
A B
sku custom_option_row_sku
AGR370A AGR370A-3, AGR370A-4, AGR370A-5, etc.
內置功能是否可能實現此目的?我是否需要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。 只需從列中復制所需的數據,然后轉到要粘貼的行,右鍵單擊->選擇性粘貼->轉置。 圖標如下所示:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.