Find and FindNext for Excel VBA

后端 未结 5 1852
谎友^
谎友^ 2020-12-03 16:12

I\'ve been stuck trying to figure out what to do with this, but basically I want a way to print out the value in column B given a specific value that matches column A. So fo

5条回答
  •  星月不相逢
    2020-12-03 17:00

        Function FindMultiResut(ByRef What As String, _
                                ByRef FindRng As Range, _
                                ByRef OutputRng As Range, _
                                ByRef Delimite As String)
    
            Dim fRng As Range
            Dim Rng1 As Range
            Dim Rng2 As Range
            Dim temp As String
    
            Set fRng = FindRng
            Do
                If Rng1 Is Nothing Then
                    Set Rng1 = fRng.Find(What:=What, After:=fRng(1))
                    Set Rng2 = Rng1
                Else
                    Set Rng2 = fRng.Find(What:=What, After:=Rng2)
                    If Rng2.Address = Rng1.Address Then Exit Do
                End If
    
                If OutputRng.Worksheet.Cells(Rng2.Row, OutputRng.Column) <> Empty Then
                    temp = temp & OutputRng.Worksheet.Cells(Rng2.Row, OutputRng.Column) & Delimite
                End If
            Loop
            FindMultiResut = Left(temp, Len(temp) - 1)
        End Function
    

提交回复
热议问题