【发布时间】:2016-05-06 10:45:02
【问题描述】:
我有 4 列的名称列表。所有列都来自不同的 excel 文件。我希望 E 列中单元格的值在 Y 或 N 中发生变化,具体取决于是否在其他列 A、B、C 中找到了 D 列中的值:
-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 公式
-
我同意@Phil。这可以使用公式来完成。除非我误解了你的问题。
-
嗨,我尝试过使用 count if、条件格式、5 if's ... 但它不起作用。
-
您要针对 A1,B1,C1 还是针对所有列 A,B,C来测试 D1 > ??
-
嗨,案例 1:在 A:B 范围内搜索 D1,如果未找到,则在 C:C 范围内搜索。如果找不到 E1 显示 Y 。案例 2:在 A:A 范围内搜索 D1 - 如果找到,则 E1 显示 N 。