创建一个搜索框,将所有结果生成一个新的工作表

时间:2019-06-19 15:36:44

标签: excel vba

我有一个带有供应商联系人的表,该表有800多行。我需要创建一个搜索框,有点像google,嘿,我正在寻找供应商名称,它可以通过过滤器为我提供工作表中供应商名称下的所有联系方式,就像过滤器一样。我所拥有的只是用于搜索的VBA代码,它可以告诉您单元格的结果。我需要它才能真正为我提供结果。

以下是我根据搜索可以提供的所有信息

Sub FindEmAll()
    Dim strFind As String
    Dim wsh As Worksheet
    Dim rng As Range
    Dim strAddress As String
    Dim strMsg As String
    strFind = InputBox("Enter the value to search for")
    If strFind = "" Then
        MsgBox "Exit stage left.", vbInformation
        Exit Sub
    End If
    For Each wsh In Worksheets
        With wsh.Cells
            Set rng = .Find(What:=strFind, LookAt:=xlWhole)
            If Not rng Is Nothing Then
                strAddress = rng.Address
                Do
                    strMsg = strMsg & vbCrLf & wsh.Name & "!" & rng.Address
                    Set rng = .FindNext(After:=rng)
                Loop Until rng.Address = strAddress
            End If
        End With
    Next wsh
    If strMsg = "" Then
        MsgBox strFind & " was not found.", vbInformation
    Else
        MsgBox strFind & " was found in:" & vbCrLf & strMsg, vbInformation
    End If
End Sub

0 个答案:

没有答案