结果取决于如果值发现excel vba

我有4列与名单。 所有列都来自不同的Excel文件。 我想要来自列E的单元格中的值改变为Y或N,具体取决于列D中的值是否在其他列A,B,C中find:

-Y: (if D is found in A) -N: (if D is found in A and B) or (if D is found in C) or (if D is not found in A and B and C) 

这是我到现在为止:

 Sub find_if_in_a_and_b() Dim FindString As String Dim Rng As Range Findcell = Sheets("Sheet1").Range("D:D") If Trim(Findcell) <> "" Then With Sheets("Sheet1").Range("A:B") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub Sub find_if_in_a_and_b_and_c() Dim FindString As String Dim Rng As Range Findcell = Sheets("Sheet1").Range("D:D") If Trim(Findcell) <> "" Then With Sheets("Sheet1").Range("A:C") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then Application.Goto Rng, True Else MsgBox "Nothing found" End If End With End If End Sub 

欢迎任何帮助。谢谢。 在这里输入图像说明

像队友说,你不需要VBA。 使用此公式为COUNTIF(A:A;$D2)制作3个辅助列,并在其中查找“Y”或“N”。检查此图像 在这里输入图像说明