我在Excel中有三列:
Column A: Category
Column B: Value
Column C: Value
我想合并列表,如果我有如下所示的行:
A1:Car | B1:Ford | C1:Toyota
A2:Scooter | B2:Honda | C2:(blank)
A3:Bike | B3:Yamaha | C3:Ducati
给我一个结果:
A1:Car | B1:Ford
A2:Car | B2:Toyota
A3:Scooter | B3:Honda
A4:Bike | B4:Yamaha
A5:Bike | B5:Ducati
答案 0 :(得分:0)
无需编程,只需复制粘贴。
第0步:保存为新页:)
答案 1 :(得分:0)
以下代码可以解决这个问题,因为这一切都发生在活动表上。
Sub consolidate()
Dim lastRow As Integer
Dim lastCol As Integer
Dim counterRow As Integer
Dim counterCol As Integer
Dim counterDestinationRow As Integer
Dim destination As Object
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
Set destination = Cells(lastRow + 2, 1)
'or to another sheet: Set destination = Sheets("Sheet2").Cells(1, 1)
For counterRow = 1 To lastRow
lastCol = Cells(counterRow, Columns.Count).End(xlToLeft).Column
For counterCol = 2 To lastCol
destination.Offset(counterDestinationRow, 0) = Cells(counterRow, 1)
destination.Offset(counterDestinationRow, 1) = Cells(counterRow, counterCol)
counterDestinationRow = counterDestinationRow + 1
Next counterCol
Next counterRow
End Sub