|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
借用论坛的一段代码,实现了我想要的功能——合并相同行并把指定列的数据相加
- Sub hebing()
- Dim d, Arr, Brr, RowNum, ColNum
- Set d = CreateObject("Scripting.Dictionary")
- RowNum = Sheet1.Range("a65536").End(xlUp).Row
- ColNum = Sheet1.Range("Z1").End(xlToLeft).Column
- Arr = Sheet1.Range("A1:J" & ColNum)
- ReDim Brr(1 To RowNum, 1 To ColNum)
- For i = 2 To UBound(Arr)
- s = Arr(i, 1) & Arr(i, 2) & Arr(i, 3) & Arr(i, 4) & Arr(i, 5) & Arr(i, 7) & Arr(i, 8) & Arr(i, 9) & Arr(i, 10)
- If d(s) = "" Then
- m = m + 1
- d(s) = m
- For J = 1 To UBound(Arr, 2)
- Brr(m, J) = Arr(i, J)
- Next
- Else
- Brr(d(s), 6) = CLng(Brr(d(s), 6)) + CLng(Arr(i, 6))
- End If
- Next
- Sheet3.[A2:L1000] = ""
- Sheet3.Columns("A:E").NumberFormatLocal = "@"
- Sheet3.[A2].Resize(m, UBound(Brr, 2)) = Brr
- End Sub
复制代码 不过在把这个宏制作成加载宏以后,运行宏并没有反应,必须把这段代码写进当前sheet1工程里面才可以
NG
OK
求各路大神指点迷津,不甚感激!
|
|