VBA If,Then Statement [英] VBA If, Then Statement
问题描述
您好...我正在尝试创建数据兼容性工具,但无法使下面的代码/公式完全正常工作。第一行工作正常但后续行在输入值时不执行任何操作。非常感谢您提供的任何帮助。谢谢
提前。
私人子工作表_更改(按范围作为目标)
如果工作表(1).Range("A2")="0A"和工作表(1).Range(" B2")=" F"或工作表(1)。范围("B2")=" G"然后
工作表(1).Range(" C2")=" YES"
  ;
其他
工作表(1)。范围("C2")="否"&b。    
结束如果
End Sub
这是一个用于Net论坛的VB,它使用Or和OrElse来代替AndIf
但是,确定你的问题是在语句周围添加括号。
这是VBA论坛
Hello...I am trying to create a data compatibility tool and can't get the below code/formula to work fully. The first row works fine but the subsequent rows do nothing when values are entered. Any assistance you can provide is greatly appreciated. Thanks in advance.
Private Sub Worksheet_Change(ByVal Target As Range)
If Worksheets(1).Range("A2") = "0A" And Worksheets(1).Range("B2") = "F" Or Worksheets(1).Range("B2") = "G" Then
Worksheets(1).Range("C2") = "YES"
Else
Worksheets(1).Range("C2") = "NO"
End If
End Sub
This is a VB for Net forum which uses instead of Or and And OrElse and AndIf
However, for sure your problem is in adding parenthesis around the statements.
This is the VBA forum
这篇关于VBA If,Then Statement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!