hi,
this code will ask you for the name you want to search on then stop at every occurance of that name
Sub searchname_Click()
Dim ThisAddress$, Found, FirstAddress
Dim Lost$, N&, NextSheet&
Dim CurrentArea As Range, SelectedRegion As Range
Dim Reply As VbMsgBoxResult
Dim FirstSheet As Worksheet
Dim Ws As Worksheet
Dim Wks As Worksheet
Dim Sht As Worksheet
Set FirstSheet = ActiveSheet '< bookmark start sheet
Lost = InputBox(prompt:="Type in the book details you are looking for!", _
Title:=" Find what?", Default:="*")
If Lost = Empty Then End
For Each Ws In Worksheets
Ws.Select
With ActiveSheet.Cells
Set FirstAddress = .Find(What:=Lost, LookIn:=xlValues)
If FirstAddress Is Nothing Then '< blank sheet
GoTo NextSheet
End If
FirstAddress.Select
With Selection
Set Found = .Find(What:=Lost, LookIn:=xlValues)
If Not Found Is Nothing Then
FirstAddress = Found.Address
End If
End With
Selection.Copy
Reply = MsgBox("Is this the " & Lost & " you're looking for?", _
vbQuestion + vbYesNoCancel)
Set Found = .Find(What:=Lost, LookIn:=xlValues)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
Set Found = .FindNext(Found)
Loop While Not Found Is Nothing And Found. _
Address <> FirstAddress
End If
Set FirstAddress = .Find(What:=Lost, LookIn:=xlValues)
If Reply = vbCancel Then End
If Reply = vbYes Then
Set SelectedRegion = Selection
GoTo Finish:
End If
ThisAddress = FirstAddress.Address
Set CurrentArea = Selection
Do
If Intersect(CurrentArea, Selection) Is Nothing Then
With Selection
Set Found = .Find(What:=Lost, LookIn:=xlValues)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
Set Found = .FindNext(Found)
Loop While Not Found Is Nothing And Found. _
Address <> FirstAddress
End If
End With
Selection.Copy
' Range("h1").Select
' ActiveSheet.Paste
Reply = MsgBox("Is this the " & Lost & " you're looking for?", _
vbQuestion + vbYesNoCancel, "Current Region")
Set Found = .Find(What:=Lost, LookIn:=xlValues)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Set Found = .FindNext(Found)
End If
Set FirstAddress = .Find(What:=Lost, _
LookIn:=xlValues)
If Reply = vbCancel Then End
If Reply = vbYes Then
GoTo Finish:
End If
End If
If CurrentArea Is Nothing Then
Set CurrentArea = Selection
Else
Set CurrentArea = Union(CurrentArea, Selection)
End If
Set FirstAddress = .FindNext(FirstAddress)
FirstAddress.Select
Loop While Not FirstAddress Is Nothing And FirstAddress. _
Address <> ThisAddress
End With
NextSheet:
Next Ws
Finish:
If Reply = vbYes Then
Exit Sub
Else
FirstSheet.Select
MsgBox "Search Completed - Sorry, no more " & Lost & "s", _
vbInformation, "No Region Selected"
End If
End Sub
steve
Bookmarks