答案1
答案2
打开 Visual Basic(按Alt+F11)
插入一个模块并将以下代码粘贴到该模块中
Sub Macro()
Dim i As Integer, j As Integer, k As Integer, LastRow As Integer
LastRow = Sheets(1).Range("A1").End(xlDown).Row
Sheets(2).Cells(1, 1).Value = Sheets(1).Cells(1, 1).Value
Sheets(2).Cells(1, 2).Value = Sheets(1).Cells(1, 2).Value
k = 1
j = 2
For i = 1 To LastRow
If Sheets(1).Range("A" & i).Value = Sheets(1).Range("A" & (i + 1)).Value Then
j = j + 1
Sheets(2).Cells(k, j).Value = Sheets(1).Cells(i + 1, 2).Value
Else
k = k + 1
Sheets(2).Cells(k, 1).Value = Sheets(1).Cells(i + 1, 1).Value
Sheets(2).Cells(k, 2).Value = Sheets(1).Cells(i + 1, 2).Value
j = 2
End If
Next i
End Sub
此代码检查第一列单元格之间的相似性,如果单元格内容匹配,则其旁边单元格中的值将被复制到另一张表。如果第一列单元格内容不匹配,则它将被视为下一个数据点。