VBA计算器的全部实现
Posted letben
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA计算器的全部实现相关的知识,希望对你有一定的参考价值。
我们将加入 除零逻辑 和 对话框提示。
后面 就很简单了~~~
提供效果图跟 代码
代码示例
Sub 矩形1_Click() ‘ ‘ 矩形1_Click Macro ‘ 代码编辑 Dim number1 As Integer Dim number2 As Integer number1 = Cells(5, 4) number2 = Cells(6, 4) Cells(7, 4) = number1 + number2 End Sub Sub 矩形2_Click() ‘ ‘ 矩形2_Click Macro ‘ Dim number1 As Integer Dim number2 As Integer number1 = Cells(5, 4) number2 = Cells(6, 4) Cells(7, 4) = number1 - number2 End Sub Sub 矩形4_Click() ‘ ‘ 矩形4_Click Macro ‘ Dim number1 As Integer Dim number2 As Integer number1 = Cells(5, 4) number2 = Cells(6, 4) Cells(7, 4) = number1 * number2 End Sub Sub 矩形5_Click() ‘ ‘ 矩形5_Click Macro ‘ number1 = Cells(5, 4) number2 = Cells(6, 4) If number2 = 0 Then MsgBox ("除数不能为零~") Else Cells(7, 4) = number1 / number2 End If End Sub
参考文献:
https://www.yiibai.com/vba/vba_message_box.html
以上是关于VBA计算器的全部实现的主要内容,如果未能解决你的问题,请参考以下文章