简体   繁体   English

Excel中的逻辑运算符:如果不是

[英]Logical Operators in Excel: If Not

I'm new in Excel VBA programming and I am trying to do the following within a Macro: 我是Excel VBA编程的新手,我正在尝试在宏中执行以下操作:

  If Not Sheets(Currencies).Range("B2") <> "USD" Then
    Sheets(Currencies).Range("B2").Value = "=USD"
        Call Sheet3.UpdateCurrencyList
End If

EDIT: I have fixed the codes from the comments below, but now I get runtime 9 error. 编辑:我已经从下面的注释中修复了代码,但是现在我得到运行时9错误。

There are 2 errors: 有两个错误:

  1. there arent double quotes in the first row before and after Currencies 货币前后第一行中都没有双引号
  2. USD is not a formula but a value 美元不是公式而是值

Try this: 尝试这个:

Sub MySub()

If Not Sheets("Currencies").Range("B2") = "USD" Then
    Sheets("Currencies").Range("B3").Value = "USD"
        Call Sheet3.UpdateCurrencyList
    Else
End If

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM