Oh sorry I misread your post. I will go ahead and post this one as another option, because i recently posted it for someone else, and it is probably the macro i use more frequently than anyother. IT will create a new page, returning all occurrences of your seaRch. It will also add hyperlinks with cell addresses for each occurrence.
Option Compare Text
Option Explicit
Public Sub DoFindAll()
FindAll "", "True"
End Sub
Sub FindAll(Search As String, Reset As Boolean)
Dim WB As Workbook
Dim WS As Worksheet
Dim Cell As Range
Dim Prompt As String
Dim Title As String
Dim FindCell() As String
Dim FindSheet() As String
Dim FindWorkBook() As String
Dim FindPath() As String
Dim FindText() As String
Dim Counter As Long
Dim FirstAddress As String
Dim path As String
If Search = "" Then
Prompt = "What dates do you want to search for in the worbook: " & _
vbNewLine & vbNewLine & path
Title = "Date Search"
Search = InputBox(Prompt, Title, "Date ranges to search for:")
If Search = "" Then
GoTo Cancelled
End If
End If
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
On Error GoTo Cancelled
Set WB = ActiveWorkbook
For Each WS In WB.Worksheets
If WS.Name <> "Date Results Search" Then
With WB.Sheets(WS.Name).Range("A:Z")
Set Cell = .Find(What:=Search, LookIn:=xlValues, LookAt:=xlPart, _
MatchCase:=False, SearchOrder:=xlByColumns)
If Not Cell Is Nothing Then
FirstAddress = Cell.Address
Do
Counter = Counter + 1
ReDim Preserve FindCell(1 To Counter)
ReDim Preserve FindSheet(1 To Counter)
ReDim Preserve FindWorkBook(1 To Counter)
ReDim Preserve FindPath(1 To Counter)
ReDim Preserve FindText(1 To Counter)
FindCell(Counter) = Cell.Address(False, False)
FindText(Counter) = Cell.Text
FindSheet(Counter) = WS.Name
FindWorkBook(Counter) = WB.Name
FindPath(Counter) = WB.FullName
Set Cell = .FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> FirstAddress
End If
End With
End If
Next
If Counter = 0 Then
MsgBox Search & " was not found.", vbInformation, "Zero Dates found"
GoTo Cancelled
End If
On Error Resume Next
Sheets("Date Results Search").Select
If Err <> 0 Then
ThisWorkbook.Sheets("Date Results Search").Copy Before:=ActiveWorkbook.Worksheets(1)
End If
Dim wsTest As Worksheet
Const strSheetName As String = "Date Results Search"
Set wsTest = Nothing
On Error Resume Next
Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
On Error GoTo 0
If wsTest Is Nothing Then
Worksheets.Add.Name = strSheetName
End If
On Error GoTo Cancelled
Range("A3", ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell)).ClearContents
Range("A1:B1").Interior.ColorIndex = 35
Range("A1").Value = "All Occurances of :"
If Reset = True Then Range("B1").Value = Search
Range("A1:D2").Font.Bold = True
Range("A2").Value = "LINK TO RESULTS"
Range("B2").Value = "RESULTS"
Range("A1:B1").HorizontalAlignment = xlLeft
Range("A2:B2").HorizontalAlignment = xlCenter
With Columns("A:A")
.ColumnWidth = 14
.VerticalAlignment = xlTop
End With
With Columns("B:B")
.ColumnWidth = 50
.VerticalAlignment = xlCenter
.WrapText = True
End With
For Counter = 1 To UBound(FindCell)
ActiveSheet.Hyperlinks.Add Anchor:=Range("A" & Counter + 2), _
Address:="", SubAddress:="'" & FindSheet(Counter) & "'" & "!" & FindCell(Counter), _
TextToDisplay:=FindSheet(Counter) & " - " & FindCell(Counter)
Range("B" & Counter + 2).Value = FindText(Counter)
Range("C" & Counter + 2).Value = _
Sheets(FindSheet(Counter)).Range(FindCell(Counter)).Offset(0, 1)
Range("D" & Counter + 2).Value = _
Sheets(FindSheet(Counter)).Range(FindCell(Counter)).Offset(0, 2)
'*********************************************
Next Counter
'Find search term and colour text
ColourText
Cancelled:
Set WB = Nothing
Set WS = Nothing
Set Cell = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Sub ColourText()
Dim Strt As Long, x As Long, i As Long
Columns("B:B").Characters.Font.ColorIndex = xlAutomatic
For i = 3 To Range("B" & Rows.Count).End(xlUp).Row
x = 1
Do
Strt = InStr(x, Range("B" & i), [B1], 1)
If Strt = 0 Then Exit Do
Range("B" & i).Characters(Start:=Strt, _
Length:=Len([B1])).Font.ColorIndex = 7
x = Strt + 1
Loop
Next
End Sub
Bookmarks