excel2010如何快速把矩形表格的数据排成一列然后合并同类项
发布网友
发布时间:2022-08-16 01:58
我来回答
共1个回答
热心网友
时间:2023-09-26 10:03
可以使用VBA操作。
Sub Combine()
Cells(1, 1) = "品名"
Cells(1, 2) = "重量"
Dim myRange, myRange1 As Range
Dim i As Single
Set myRange = Application.InputBox("选择汇总区域", Default:="D5:I100", Type:=8)
For Each myRange1 In myRange
Dim Flag As Single
Flag = 0
If myRange1 <> "" And Not IsNumeric(myRange1) Then
Dim myRow As Single
myRow = Cells(65536, 1).End(xlUp).Row
For i = 2 To myRow
If myRange1.Value = Cells(i, 1) Then
Flag = 1
Exit For
End If
Next
If Flag = 1 Then
Cells(i, 2).Value = Cells(i, 2).Value + myRange1.Offset(0, 1).Value
Flag = 0
Else
Cells(myRow + 1, 1) = myRange1.Value
Cells(myRow + 1, 2) = myRange1.Offset(0, 1).Value
End If
End If
Next
End Sub