
Option Explicit
Private Sub CommandButton1_Click()
Dim A1 As Single, A2 As Single
A1 = CSng(TextBox1.Value)
A2 = CSng(TextBox2.Value)
Label3.Caption = (A1 - A2) / A1 * 100
End Sub
Private Sub TextBox1_Change()
On Error Resume Next'防止一开始为空时出错
If (TextBox1.Value) = Empty Or CSng(TextBox1.Value) = "0" Then 'A1 不能为空或 0
CommandButton1.Locked = True'锁住“计算”键
Else
If Not (TextBox2.Value = Empty) Then' A1 是不为 0 的数字且 A2 也不空
CommandButton1.Locked = False '解锁 “计算”键
End If
End If
Label3.Caption = Empty
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii >47 And KeyAscii <58) Or KeyAscii = 46) Or Not (IsNumeric(TextBox1.Value &Chr(KeyAscii))) Then
KeyAscii = 8'防止输出的不是数字
End If
End Sub
Private Sub TextBox2_Change()
On Error Resume Next'防止一开始为空时出错
If (TextBox1.Value) = Empty Or CSng(TextBox1.Value) = "0" Then 'A1 不能为空或 0
CommandButton1.Locked = True'锁住“计算”键
Else
If Not (TextBox2.Value = Empty) Then' A1 是不为 0 的数字且 A2 也不空
CommandButton1.Locked = False '解锁 “计算”键
End If
End If
Label3.Caption = Empty
End Sub
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not ((KeyAscii >47 And KeyAscii <58) Or KeyAscii = 46) Or Not (IsNumeric(TextBox2.Value &Chr(KeyAscii))) Then
KeyAscii = 8'防止输出的不是数字
End If
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = Empty
TextBox2.Value = Empty
Label3.Caption = Empty
CommandButton1.Locked = True
End Sub
1、首先打开Excel,以制作一个抽奖小程序为例,先输一些数据。2、首先我们在抽奖区的单元格中输入=INDEX()。
3、然后选中数据源,也就是所有成员。
4、然后继续输入=INDEX(E:E,Randbetween())。
5、在Randbetween()这个涵数中输入1,5,也就是数据源。
6、输入完成后,回车确认,这样一个抽奖小程序就制作好了。可以按以上抽奖小程序的方法来制作ph计算小程序。
1,第一步,打开Excel表格程序,进入程序主界面,输入一个固定值。
2,第二步,在单元格内输入以下的公式,回车确定。
3,第三步,看到除法公式计算完成,向下填充公式。
4,最后,即可看到整列除于一个数完成,问题解决。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)