excel的宏问题
Inventory Template_For JW.zip
(156.12 KB)
KANBAN为产品型号 QTY为个数 求汇总后 几个相同的产品型号 叠加为一个 后面的个数相加
代码如下
Private Sub mySumTotal()
Dim m, n, r As Integer
Sheets("Total").Select
Range("A2").Select
Selection.CurrentRegion.Select
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1, Selection.Columns.Count).Select
Selection.Clear
Sheets("Index").Select
Range("A2").Select
MySheetNumber = Application.WorksheetFunction.CountA(Range("B:B")) - 1
m = 1: r = 2
Do Until m > MySheetNumber
MySheet = Sheets("Index").Range("B" & CStr(1 + m))
Sheets(MySheet).Activate
Range("A2").Select
n = Application.WorksheetFunction.CountA(Range("B:B"))
If n = 1 Then GoTo Halt:
Range("A2:D" & CStr(n)).Copy 'Union(Range("A2:D" & CStr(n)), Range("I2:I" & CStr(n))).Copy
Sheets("Total").Select
Range("A" & CStr(r)).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Halt: m = m + 1
If n = 1 Then
r = r
Else
r = r + n - 1
End If
Loop
Sheets("Total").Select
Range("A2").Select
End Sub