从InputBox获取数学运算符 [英] Get Math Operator from InputBox
本文介绍了从InputBox获取数学运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用InputBox获取数学运算符
I am trying to use InputBox to get a math operator
例如:+
.当我用变量替换运算符时,会出现错误
E.g.: +
. When I replace the operator with the variable it gives an error
然后预期或转到
Expected Then or GoTo
这不起作用:
Sub NumTest()
Dim Val As Integer
Val = Application.InputBox("Value", "Value", Type:=1)
oper = Application.InputBox("Op")
rcell = Range("D2")
If rcell oper Val = True Then
MsgBox "True"
End If
End Sub
这确实有效:
Sub NumTest()
Dim Val As Integer
Val = Application.InputBox("Value", "Value", Type:=1)
oper = Application.InputBox("Op")
rcell = Range("D2")
If rcell > Val = True Then
MsgBox "True"
End If
End Sub
推荐答案
创建一个字符串并使用Application.Evaluate:
Create a string and use Application.Evaluate:
Sub NumTest()
Dim Val As Integer
Val = Application.InputBox("Value", "Value", Type:=1)
Dim oper As String
oper = Application.InputBox("Op")
Dim rcell As String
rcell = ActiveSheet.Range("D2")
If Application.Evaluate(rcell & oper & Val) Then
MsgBox "True"
Else
MsgBox "False"
End If
End Sub
这篇关于从InputBox获取数学运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文