Vba Cell值为Expression

问题描述 投票:0回答:1

我在单元格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"
vba expression
1个回答
0
投票

如果你在<1000A1这样的东西会返回你需要的东西

Sub TestMe
    Debug.Print CBool(Evaluate(900 & Cells(1,1)))
End Sub

整个代码,写信给A1并检查FalseTrue场景:

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
© www.soinside.com 2019 - 2024. All rights reserved.