여기 있습니다. XlFindAll 함수는이 목적을 위해 사용자 정의 작성된 것이 아니라 사용자 정의 된 것입니다. 따라서 불필요한 코드가 포함되어 있습니다.
Sub TestFindAll()
' 23 Dec 2017
Dim Ws As Worksheet
Dim Rng As Range ' range to search in
Dim Matches As String
Dim R As Long, Rl As Long
Set Ws = ActiveSheet
Application.ScreenUpdating = False
With Ws
Rl = .Cells(.Rows.Count, "B").End(xlUp).Row
' search items are in column B, starting in row 2
Set Rng = Range(.Cells(2, "B"), .Cells(Rl, "B"))
' matches will be returned form the adjacent column
' however this can be adjusted in the XlFindAll function
For R = 2 To Rl
Matches = XlFindAll(Rng, .Cells(R, "B").Value)
If Len(Matches) Then
' output to column D
.Cells(R, "D").Value = .Cells(R, "B").Value & " (" & Matches & ")"
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
Function XlFindAll(Where As Range, _
ByVal What As Variant, _
Optional ByVal LookIn As Variant = xlValues, _
Optional ByVal LookAt As Long = xlWhole, _
Optional ByVal SearchBy As Long = xlByColumns, _
Optional ByVal StartAfter As Long, _
Optional ByVal Direction As Long = xlNext, _
Optional ByVal MatchCase As Boolean = False, _
Optional ByVal MatchByte As Boolean = False, _
Optional ByVal After As Range, _
Optional ByVal FindFormat As Boolean = False) As String
' 23 Dec 2017
' Settings LookIn, LookAt, SearchOrder, and MatchByte
' are saved each time the Find method is used
Dim Fun() As String
Dim Search As Range
Dim Fnd As Range
Dim FirstFnd As String
Dim i As Long
Set Search = Where
With Search
If After Is Nothing Then
If StartAfter Then
StartAfter = WorksheetFunction.Min(StartAfter, .Cells.Count)
Else
StartAfter = .Cells.Count
End If
Set After = .Cells(StartAfter)
End If
Set Fnd = .Find(What:=What, After:=After, _
LookIn:=LookIn, LookAt:=LookAt, _
SearchOrder:=SearchBy, SearchDirection:=Direction, _
MatchCase:=MatchCase, MatchByte:=MatchByte, _
SearchFormat:=FindFormat)
If Not Fnd Is Nothing Then
FirstFnd = Fnd.Address
ReDim Fun(100)
Do
' select the value in the adjacent cell on the same row
Fun(i) = Fnd.Offset(0, 1).Value
i = i + 1
Set Fnd = .FindNext(Fnd)
Loop While Not (Fnd Is Nothing) And (Fnd.Address <> FirstFnd)
End If
End With
If i Then ReDim Preserve Fun(i - 1)
XlFindAll = Join(Fun, "-")
End Function
이미 몇 가지 답변을 얻었으나 어떤 시도를했는지 보여 줄 수 있습니까? –
나는 한 번 완료되면 여기에 게시 할 것들을 시도 중이다. – CJanon
사전 객체를 사용하는 또 하나의 접근법. 동일한 결과를 제공해야합니다. –