|
Sub 出入库明细()
Dim r%, i%, c%, j%, m%, k%
Dim arr, brr, crr, brr1, crr1, drr, sm
Dim rq As Date
Dim d As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
lk = Array(20, 8, 8, 8)
Set d = CreateObject("scripting.dictionary")
nf = Application.InputBox(prompt:="请输入统计年份", Title:="操作提示", Default:=Year(Date), Type:=1)
If TypeName(nf) = "Boolean" Then
Exit Sub
End If
tt = Timer
With ThisWorkbook.Worksheets("出入库明细")
.AutoFilterMode = False
r = .Cells(.Rows.Count, 3).End(xlUp).Row
c = .Cells(1, .Columns.Count).End(xlToLeft).Column
arr = .Range("a2").Resize(r - 1, c)
End With
ReDim brr(1 To UBound(arr), 1 To 5)
For i = 1 To UBound(arr)
If arr(i, 3) <> "" Then
s = arr(i, 3)
If Not d.exists(s) Then
m = m + 1
d(s) = m
brr(m, 1) = arr(i, 3)
End If
If Year(arr(i, 1)) < nf Then
brr(d(s), 2) = brr(d(s), 2) + arr(i, 7) - arr(i, 8)
End If
If Year(arr(i, 1)) = nf Then
brr(d(s), 3) = brr(d(s), 3) + arr(i, 7)
brr(d(s), 4) = brr(d(s), 4) + arr(i, 8)
End If
brr(d(s), 5) = brr(d(s), 5) + arr(i, 7) - arr(i, 8)
End If
Next
If d.Count = 0 Then
MsgBox "没有符合条件数据!"
Exit Sub
End If
With ThisWorkbook.Worksheets("库存汇总表")
.Range("a3").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row, 52).Clear
With .Range("a3").Resize(m, 5)
.Value = brr
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter ' 单元格居中
With .Font
.Name = "times new roman"
.Size = 12
End With
End With
With .Cells(m + 3, 1)
.Value = "合计"
End With
For x = 2 To 5
With .Cells(m + 3, x)
.Value = Application.Sum(Application.Index(brr, 0, x))
End With
Next x
With .Range(.Cells(m + 3, 1), .Cells(m + 3, 5))
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter ' 单元格居中
With .Font
.Name = "times new roman"
.Size = 12
.Bold = True
End With
.Interior.Color = 11389944
End With
With .Range("b3").Resize(m + 1, 4)
.NumberFormat = "0_ " '设置单元格数字格式
.HorizontalAlignment = xlRight ' 单元格居右
End With
With .Cells(4 + m, 2).Resize(1)
.Value = "上次统计时间:" & Format(Date, "yyyy年m月d日")
With .Font
.Name = "times new roman"
.Size = 12
End With
End With
End With
r = m + 2
ActiveWorkbook.Worksheets("库存汇总表").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("库存汇总表").Sort.SortFields.Add Key:=Range("A3:A" & r), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("库存汇总表").Sort
.SetRange Range("A3:E" & r)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
|
评分
-
1
查看全部评分
-
|