|
本帖最后由 kklee96 于 2024-6-22 09:24 编辑
Sub TEST() '自动排序汇总相同物料的数量
Dim x&, i&, k, j&
Dim str1$
Worksheets("出货明细表").Range("A2:K65536").Sort _
Key1:=Range("d2"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
j = Range("D65536").End(xlUp).Row '获取D列物料编码
i = 2
str1 = Range("D2") '从D列第一个物料编码开始
For x = 2 To j
If Cells(x, 4) = str1 Then '物料编码在工作表第4列
k = k + Cells(x, 6) '数量在工作表第6列
Else
Cells(i, 12) = k '数量汇总在工作表第12列
k = Cells(x, 6) '数量在工作表第6列
i = x
str1 = Cells(x, 4) '物料编码在工作表第4列
End If
Next x
Cells(i, 12) = k '数量汇总在工作表第12列
t = [d65536].End(2).Row
If t > 1 Then
Range("L1:L" & t + 1).Borders(xlInsideHorizontal).Weight = xlThin '线框
Range("A2:K65536").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$D4<>$D3"
Selection.FormatConditions(1).Borders(xlLeft).LineStyle = xlNone
Selection.FormatConditions(1).Borders(xlRight).LineStyle = xlNone
Selection.FormatConditions(1).Borders(xlTop).LineStyle = xlNone
With Selection.FormatConditions(1).Borders(xlBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 2
Range("L1") = Format(Now, "yyyy-m-d") '日期在L2单元格上
End With
End If
End Sub
以上代码只判断D列数值相同时,F列根据D列相同的数值进行排序,数据进行合计,怎么修改成同时满足A列和D列条件时,D列排序数量相加,如A81-A83行,A82跟A81和A83不同,但F列数量合计在一起了,现要把如A82行数量单独合计,麻烦帮忙修改下,谢谢!
补充内容 (2024-6-24 11:10):
|
-
|