结果取决于是否找到值Excel VBA [英] Results depending if value found excel vba
本文介绍了结果取决于是否找到值Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有4列带有名称列表的列.所有列均来自不同的excel文件.我希望来自E列的单元格的值在Y或N中变化,具体取决于是否在其他A,B,C列中找到了D列的值:
I have 4 columns with names list. All columns are from different excel files. I want the value from cells from column E to change in Y or N depending if the value from column D is found in other columns A,B,C:
-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)
这是我到目前为止所拥有的:
This is what i have until now :
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
欢迎任何帮助.谢谢.
Any help is welcomed.Thank you.
推荐答案
就像队友说的那样,您不需要VBA.用此公式 COUNTIF(A:A; $ D2)
用在A中找到",在B中找到在C中"创建3个辅助列,并检查Y或N.检查此图像
Like mates said, you dont need VBA. Make 3 auxiliary columns with "Found in A" "Found in B" "Found in C" with this formula COUNTIF(A:A;$D2)
and check for Y or N. Check this image
这篇关于结果取决于是否找到值Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文