首页 > 解决方案 > 使用多个条件查找价值

问题描述

我需要根据 2 个标准在 Excel 工作表中找到一个值。Find 方法仅支持一个条件。有没有其他功能?例如有 2 列。我需要在 A 列中找到 ABC,其中 B 列中的值为 10。

谢谢您的帮助

标签: vba

解决方案


想到的第一种方法。我相信还有其他方法,可能更好。

'VBA Loop Not exactly recommended if the file is long
Set wk = ThisWorkbook
With wk.Sheets("SheetName")
    lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 to lastRow
        aString = .Cells(i, 1).Text
        bString = .Cells(i, 2).Text
        If aString & bString = "ABC10" Then
            MsgBox "Found at Row: " & i
            Exit For
        End If
    Next i
End With

推荐阅读