【发布时间】:2021-11-04 08:29:19
【问题描述】:
我试图用 Excel VBA 做的是在表格中搜索多个条件,如果我得到这些条件的多个结果,我想显示它们。 到目前为止,我的代码可以搜索多个条件,但在找到一个匹配结果时停止。
作为一个初学者,我想请你帮忙看看如何实现多结果的功能。
这是我现在使用的代码 sn-p:
Set rngSearch = Sheets(Temp_Bereich).Range("A:M")
Set Found = rngSearch.Find(What:=Material_A, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Found Is Nothing Then
Firstfound = Found.Address
Do
If Found.EntireRow.Range("B1").Value = Material_B And _
Found.EntireRow.Range("C1").Value = Schmierzustand_AB And _
Found.EntireRow.Range("G1").Value = Rauheit_A And _
Found.EntireRow.Range("H1").Value = Rauheit_B And _
Found.EntireRow.Range("D1").Value = Schmiermittel_AB Then Exit Do 'Match found
Set Found = rngSearch.FindNext(After:=Found)
If Found.Address = Firstfound Then Set Found = Nothing
Loop Until Found Is Nothing
End If
If Not Found Is Nothing Then
Application.Goto Found.EntireRow
Haftreibwert.Value = Cells(Found.Row, 12).Value
Gleitreibwert.Value = Cells(Found.Row, 13).Value
Else
MsgBox "Es trifft leider nichts auf alle 6 Kriterien zu ", , "Kein Match gefunden"
End If
来自德国的问候, 菲利普
【问题讨论】:
-
你能贴一张你的桌子的图片吗?你的搜索条件是什么,因为我只显示变量。
标签: excel vba multiple-results