|
aland11 发表于 2012-12-24 16:21
我发附件吧,就是自动计算良品率和报废率
在 VBE 中双击 Sheet1(一车间) 工作表,然后把代码 Copy 进去
猜 的计算位置,代码有说明,自己照着修改吧
- Private Sub Worksheet_Change(ByVal Target As Range)
- With Target
- If .Count > 1 Then Exit Sub '如果操作的单元格个数 大于 1 则退出
- If .Row < 5 Then Exit Sub '如果操作行数 小于 5 则退出
- If InStr("4,5,7", .Column) = 0 Then Exit Sub '如果操作的不是 DEF 列,则退出
-
- If InStr(" 0", Val(Cells(.Row, "D").Value)) > 0 Then Exit Sub '如果对应 D列中数值为 0 则退出
- If InStr(" 0", Val(Cells(.Row, "E").Value)) > 0 Then Exit Sub '如果对应 E列中数值为 0 则退出
- If InStr(" 0", Val(Cells(.Row, "G").Value)) > 0 Then Exit Sub '如果对应 G列中数值为 0 则退出
-
- Application.EnableEvents = False '关闭事件
- Cells(.Row, "F").Value = Cells(.Row, "E").Value / Cells(.Row, "D").Value '计算 比例
- Cells(.Row, "H").Value = Cells(.Row, "G").Value / Cells(.Row, "D").Value '计算 比例
- Application.EnableEvents = True '打开事件
- End With
- End Sub
复制代码 |
|