


Sub 库存查询()
Dim t, st, et
' 设置工作表
Set ws1 = ThisWorkbook.Sheets("入库表")
Set ws2 = ThisWorkbook.Sheets("出库表")
Set ws3 = ThisWorkbook.Sheets("盘点表")
With Sheets("盘点表")
'生成日期
st = .[c2].Value
et = .[C3].Value
t = et - st + 1
Dim i
For i = 1 To t
' 在 b7 及以下单元格依次填入日期
.Range("b" & i + 6).Value = (st + i - 1) * 1
' 设置单元格格式为日期格式
.Range("b" & i + 6).NumberFormatLocal = "yyyy/m/d;@"
Next
'入库,出库,库存
Dim cp
cp = .[c4].Value
If cp <> "" And st <> "" And et <> "" Then
Dim ru_z, chu_z, ck
ru_z = Application.SumIfs(ws1.[C3:C100], ws1.[A3:A100], "<" & st, ws1.[B3:B100], cp)
chu_z = Application.SumIfs(ws2.[C3:C100], ws2.[A3:A100], "<" & st, ws2.[B3:B100], cp)
ck = ru_z - chu_z
.[C7] = ck
Else
MsgBox "请指定日期,产品型号"
Exit Sub
End If
End With
End Sub
ru_z, chu_z, ck 计算出来的结果怎么为0,求解