|
楼主 |
发表于 2024-1-10 15:33
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 对账()
- Dim by1!, sy1!, xy1!
- Dim frr()
- '先列出取数的月份
- by = InputBox("请输入对账月份(例如:2023-08)")
- sy = Format(DateAdd("m", -1, by), "YYYY-MM")
- xy = Format(DateAdd("m", 1, by), "YYYY-MM")
- Sheets("对账").Select
- arr = Range("a2", Cells(Rows.Count, 1).End(xlUp))
- Sheets("到款明细").Select
- brr = Range("a1").CurrentRegion
- ReDim brr1(1 To UBound(brr))
- For j = 1 To UBound(brr)
- '把对账表格的店仓号、到账日期、营收日期、应到账金额、已到账金额用\连接在一起,方便筛选
- brr1(j) = Join(Array(brr(j, 1), brr(j, 3), brr(j, 4), brr(j, 5), brr(j, 6)), "")
- Next j
- On Error Resume Next
- For i = 1 To UBound(arr)
- crr = Filter(brr1, arr(i, 1)) '按照店仓筛选符合条件的数据
- ReDim Preserve frr(1 To UBound(crr) + 1)
- For y = 0 To UBound(crr)
- frr(y + 1) = Split(crr(y), "") '数组分割,方便筛选日期,和累加金额
- Next y
- For Z = 1 To UBound(frr)
- '营收日期是上月,到账日期是本月则则把“已到账金额”加到sy1
- If InStr(frr(Z)(2), sy) > 0 And InStr(frr(Z)(1), by) > 0 Then sy1 = sy1 + frr(Z)(4)
- If InStr(frr(Z)(2), by) > 0 Then
- If InStr(frr(Z)(1), by) > 0 Then '营收日期是本月,到账日期是本月则把“已到账金额”加到by1
- by1 = by1 + frr(Z)(4)
- Else '营收日期是本月,到账不是本月则把“应到账金额”加到xy1
- xy1 = xy1 + frr(Z)(3)
- End If
- End If
- Next Z
- Sheets("对账").Cells(i + 1, "c") = Format(sy1, "0.00") '上月累计的金额写入对账表的c列
- Sheets("对账").Cells(i + 1, "d") = Format(by1, "0.00")
- Sheets("对账").Cells(i + 1, "e") = Format(xy1, "0.00")
- sy1 = 0
- by1 = 0
- xy1 = 0
- Erase frr '清空frr
- Next i
- Sheets("对账").Select
- End Sub
复制代码 |
|