我在单元格A1中有价值。 <10000,我在VBA中有价值,即。 900我想比较VBA值和单元格值表达式。
例1。
VBA Value is "900"
Excel expression (ie cell value) is "<10000"
result "TRUE"
例2。
VBA Value is "20000"
Excel expression (ie cell value) is "<10000"
result "FALSE"
如果你在<1000
有A1
这样的东西会返回你需要的东西
Sub TestMe
Debug.Print CBool(Evaluate(900 & Cells(1,1)))
End Sub
整个代码,写信给A1
并检查False
和True
场景:
Sub TestMe()
Cells(1, 1) = "<1000"
Debug.Print Evaluate(900 & Cells(1, 1))
Cells(1, 1) = ">1000"
Debug.Print Evaluate(900 & Cells(1, 1))
End Sub
关于两个条件,它取决于条件是如何给出的。如果条件是这样的:>5000000 and <10000000
那么这段代码有效:
Sub TestMe()
Cells(1, 1) = ">5000000 and <10000000"
Debug.Print Evaluate(900 & Trim(Split(Cells(1, 1), "and")(0))) And _
Evaluate(900 & Trim(Split(Cells(1, 1), "and")(1)))
End Sub