|
- Sub 仓储费用()
- Dim arr() '原始信息
- Dim brr()
- r = [a1].End(xlDown).Row
- arr = Range("a1").Resize(r, 6).Value
- Dim mydic As Object
- Set mydic = CreateObject("scripting.dictionary")
- For i = 1 To r - 1
- mydic(arr(i + 1, 2)) = 0
- Next
- i = 0
- For Each Key In mydic.keys
- i = i + 1
- mydic(Key) = i
- Next
- ReDim brr(1 To r + mydic.Count, 1 To 10)
- Dim inputDate As String
- Dim jiesuanDate As Date
- inputDateStr:
- inputDate = InputBox("结算时间是:", "请输入结算时间")
- If ChkDateFormat(inputDate) Then
- jiesuanDate = CDate(inputDate)
- Else
- MsgBox "输入的日期格式有误,请按照yyyy-mm-dd格式(如2024-2-17)重新输入"
- GoTo inputDateStr
- End If
- n = 0
- For i = 1 To r - 1 '逐行扫描原始数据
- If arr(i + 1, 4) > 0 Then '搜索进库记录
- n = n + 1
- brr(n, 1) = arr(i + 1, 2) '获取批次
- brr(n, 2) = "入" '出入库
- brr(n, 3) = arr(i + 1, 1) '时间
- brr(n, 4) = jiesuanDate '结算时间
- brr(n, 5) = arr(i + 1, 4) '数量
- kucun = brr(n, 5)
- brr(n, 6) = 0 '天数
- brr(n, 7) = 0
- brr(n, 8) = 0
- brr(n, 9) = 0
- brr(n, 10) = 0
- For j = 1 To r - 1 '从头搜索同批次出库记录
- If arr(j + 1, 5) > 0 And arr(j + 1, 2) = arr(i + 1, 2) Then
- n = n + 1
- brr(n, 1) = arr(j + 1, 2) '获取批次
- brr(n, 2) = "出" '出入库
- brr(n, 3) = arr(j + 1, 1) '变动时间
- brr(n, 4) = jiesuanDate '结算时间
- brr(n, 5) = arr(j + 1, 5) '变动数量
- kucun = kucun - brr(n, 5) '库存数量
- brr(n, 6) = arr(j + 1, 1) - arr(i + 1, 1) '天数
- If brr(n, 6) <= 5 Then
- brr(n, 7) = brr(n, 6)
- brr(n, 8) = 0
- brr(n, 9) = 0
- ElseIf brr(n, 6) <= 10 Then
- brr(n, 7) = 5
- brr(n, 8) = brr(n, 6) - 5
- brr(n, 9) = 0
- Else
- brr(n, 7) = 5
- brr(n, 8) = 5
- brr(n, 9) = brr(n, 6) - 10
- End If
- brr(n, 10) = brr(n, 5) * brr(n, 8) * 1 + brr(n, 5) * brr(n, 9) * 0.5
- Total = Total + brr(n, 10)
- End If
- Next
-
- '计算库存
- n = n + 1
- brr(n, 1) = arr(i + 1, 2) '获取批次
- brr(n, 2) = "库" '出入库
- brr(n, 3) = jiesuanDate '时间
- brr(n, 4) = jiesuanDate '结算时间
- brr(n, 5) = kucun '数量
- brr(n, 6) = jiesuanDate - arr(i + 1, 1) '天数
- If brr(n, 6) <= 5 Then
- brr(n, 7) = brr(n, 6)
- brr(n, 8) = 0
- brr(n, 9) = 0
- ElseIf brr(n, 6) <= 10 Then
- brr(n, 7) = 5
- brr(n, 8) = brr(n, 6) - 5
- brr(n, 9) = 0
- Else
- brr(n, 7) = 5
- brr(n, 8) = 5
- brr(n, 9) = brr(n, 6) - 10
- End If
- brr(n, 10) = brr(n, 5) * brr(n, 8) * 1 + brr(n, 5) * brr(n, 9) * 0.5
- Total = Total + brr(n, 10)
-
- n = n + 1
- brr(n, 1) = "小计"
- brr(n, 10) = Total
-
- Total = 0
- kucun = 0
- End If
- Next
-
- Range("G26").Resize(UBound(brr, 1), UBound(brr, 2)).Value = brr
-
- End Sub
- Function ChkDateFormat(strDate As String) As Boolean
- On Error GoTo errhandler
- Dim dateValue As Date
- dateValue = CDate(strDate)
- ChkDateFormat = True
- Exit Function
-
- errhandler:
- ChkDateFormat = False
-
- End Function
复制代码 |
|