Option Explicit
Public Function FindWhole(ByRef FindWhat As String, Optional LookInRange As Range) As String
If LookInRange Is Nothing Then Set LookInRange = ActiveSheet.Cells
Dim Target As Range, FirstAddress As String
With LookInRange
Set Target = .Find(FindWhat, LookIn:=xlValues, SearchOrder:=xlByRows, _
LookAt:=xlWhole, MatchCase:=False)
If Not Target Is Nothing Then
FirstAddress = Target.Address
Do
If Target Is Nothing Or Target.Address = FirstAddress Then
FindWhole = FindWhole & Target.Address
Else
FindWhole = FindWhole & ", " & Target.Address
End If
Set Target = .FindNext(Target)
Loop Until Target Is Nothing Or Target.Address = FirstAddress
End If
End With
Set LookInRange = Nothing
Set Target = Nothing
End Function
Public Function FindPart(ByRef WhatPart As String, Optional LookInRange As Range) As String
If LookInRange Is Nothing Then Set LookInRange = ActiveSheet.Cells
Dim Target As Range, FirstAddress As String
With LookInRange
Set Target = .Find(WhatPart, LookIn:=xlValues, SearchOrder:=xlByRows, _
LookAt:=xlPart, MatchCase:=False)
If Not Target Is Nothing Then
FirstAddress = Target.Address
Do
If Target Is Nothing Or Target.Address = FirstAddress Then
FindPart = FindPart & Target.Address
Else
FindPart = FindPart & ", " & Target.Address
End If
Set Target = .FindNext(Target)
Loop Until Target Is Nothing Or Target.Address = FirstAddress
End If
End With
Set LookInRange = Nothing
Set Target = Nothing
End Function
Public Function FindDates(ByRef FindDate As Date, Optional LookInRange As Range) As String
If LookInRange Is Nothing Then Set LookInRange = ActiveSheet.Cells
Dim Target As Range, FirstAddress As String
With LookInRange
Set Target = .Find(FindDate, LookIn:=xlFormulas, SearchOrder:=xlByRows)
If Not Target Is Nothing Then
FirstAddress = Target.Address
Do
If Target Is Nothing Or Target.Address = FirstAddress Then
FindDates = FindDates & Target.Address
Else
FindDates = FindDates & ", " & Target.Address
End If
Set Target = .FindNext(Target)
Loop Until Target Is Nothing Or Target.Address = FirstAddress
End If
End With
Set LookInRange = Nothing
Set Target = Nothing
End Function
|