Excel中自动按照货物名称实现结余累计的示例

本文介绍如何利用Excel实现对日常购入消耗货物的自动统计,包括输入值验证、结余计算及异常提示等功能,确保库存管理的准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    日常生活中,购入消耗货物常运用Excel进行相关统计,能不能实现自动统计出某类货物的结余情况呢?能。示例如下:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim Lj, jy, Ljgr, Ljxh
If Target.Row <= 1 Then Exit Sub
If Target.Column < 3 Or Target.Column > 7 Then Exit Sub
If Target.Count > 2 Then Exit Sub

'判断输入值非负数
If Target.Value < 0 And Target.Column > 3 And Target.Column < 6 Then
   MsgBox "内容不能为负值!"
   Target.Select
   Target.Value = ""
End If

If Target.Row = 2 Then
    Cells(2, 6) = Cells(2, 4) - Cells(2, 5)
End If
If Target.Row > 2 Then
    Ljgr = 0
    Ljxh = 0
    For i = 2 To Target.Row - 1
      If Cells(i, 3) = Cells(Target.Row, 3) Then
        Ljgr = Ljgr + Cells(i, 4)
        Ljxh = Ljxh + Cells(i, 5)
      End If
    Next
    '判断消耗是否大于以往结余
    If (Target.Value > Ljgr - Ljxh + Cells(Target.Row, 4)) And Target.Column = 5 Then
     MsgBox "消耗过多了!"
     Target.Value = ""
     Target.Select
    End If
    
     Cells(Target.Row, 6) = Ljgr - Ljxh + Cells(Target.Row, 4) - Cells(Target.Row, 5)
 End If
End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值