我正在尝试在几个不同的工作表中跟踪ID,我希望能够为一个条件赋予True值,而为另一个条件赋予false。这是我想要完成的伪代码。
IF sheet1.A1.value EXISTS AND DOES NOT EXIST IN sheet2.A:A OR sheet3.A:A
THEN RETURN "true"
ELSE RETURN "false"
答案 0 :(得分:1)
试试这个
Sub Sample()
Dim SearchString As String
SearchString = "Blah"
If Application.WorksheetFunction.CountIf(Sheets("Sheet1").Columns(1), SearchString) > 0 And _
Application.WorksheetFunction.CountIf(Sheets("Sheet2").Columns(1), SearchString) = 0 And _
Application.WorksheetFunction.CountIf(Sheets("Sheet3").Columns(1), SearchString) = 0 Then
'~~> Display relevant message
Else
'~~> Display relevant message
End If
End Sub
答案 1 :(得分:1)
你也可以用这样的excel公式来做到这一点:
=IF(AND(len('Sheet1'!A1)>0 , ISERROR(MATCH('Sheet1'!A1,'Sheet2'!A:A,0)), ISERROR(MATCH('Sheet1'!A1,'Sheet3'!A:A,0))) , "True", "False")
本读: