Excel表格中如何将A列重复项的相应B列数值求和并合并? 5
给你写的代码,你不要吗?
编程实现:
ALT+F11——F7——粘贴如下代码(注意换行)——F5运行
Sub mysub()
Dim i As Long, j As Long, k As Long
Range("c1") = [a1]
Range("d1") = [b1]
j = 1
For i = 2 To [a65536].End(xlUp).Row
If Range("c:c").Cells.Find(Range("a" & i), , , lookat:=xlWhole) Is Nothing Then
j = j + 1
Range("c" & j) = Range("a" & i).Value
Range("d" & j) = Range("b" & i).Value
Else
k = Range("c:c").Cells.Find(Range("a" & i), , , lookat:=xlWhole).Row
Range("d" & k) = Range("d" & k) & "," & Range("b" & i).Value
End If
Next i
End Sub
——————————————————————以下是不换行的纯代码——————
Sub mysub()
Dim i As Long, j As Long, k As Long
Range("c1") = [a1]
Range("d1") = [b1]
j = 1
For i = 2 To [a65536].End(xlUp).Row
If Range("c:c").Cells.Find(Range("a" & i), , , lookat:=xlWhole) Is Nothing Then
j = j + 1
Range("c" & j) = Range("a" & i).Value
Range("d" & j) = Range("b" & i).Value
Else
k = Range("c:c").Cells.Find(Range("a" & i), , , lookat:=xlWhole).Row
Range("d" & k) = Range("d" & k) & "," & Range("b" & i).Value
End If
Next i
End Sub
i和i+1为下标
下面内容很多的,上万行。