Can you add a message box when I click "OK" from "Do you want to continue searching for XX" that when I click "OK" but if I am at the last search and it will say "This the end of your search" do you want to "exit" then "OK" "No" so I can start searching again.
Your description is unclear with respect to your code. I cannot understand what this means grammatically:
if I am at the last search and it will say "This the end of your search" do you want to "exit" then "OK" "No" so I can start searching again.
Your For loop searches in all sheets. Inside the For loop, you have another loop to find all instances in each sheet. If the user answers "OK" to "continue searching" then it continues to search in that sheet, until it finishes and then goes to the next sheet.
If you want to "start searching again" do you mean to continue to search that sheet? Because that's what it does right now without prompting the user.
Do you mean to start over again, prompting the user for a new search string? If you do this, then it will abandon any sheets that haven't been searched yet and start a brand new search.
Or do you want to give the user a chance to exit the entire Sub? That is already done with the first prompt.
So I'm not clear on the flow you want.
Jeff
| | |會 |會 |會 |會 | |:| | |會 |會 Read the rules
Use code tags to [code]enclose your code![/code]
If Cell.Address = Addx Then If MsgBox("This is the end of your search. Do you want to continue?", _ vbQuestion + vbOKCancel) = vbCancel then Exit sub Exit Do end if
Like this?
If it does not work, try to attach sample file.
PHP Code:
Sub FindMe()
Dim Addx As String Dim Cell As Range Dim Choice As Integer Dim Found As Boolean Dim Rng As Range Dim State As Long Dim What As String Dim Wks As Worksheet
' // Input can only be Text What = InputBox(Prompt:="Please enter your search criteria", Title:="Search") If What = "" Then Exit Sub
For Each Wks In ThisWorkbook.Worksheets State = Wks.Visible If State <> xlSheetVisible Then Wks.Visible = xlSheetVisible DoEvents Set Rng = Wks.UsedRange Set Cell = Rng.Find(What, Rng.Cells(Rng.Rows.Count, Rng.Columns.Count), xlValues, xlPart, xlByRows, xlNext, False, False, False) If Not Cell Is Nothing Then Addx = Cell.Address Found = True Do Cell.Parent.Activate Cell.Select Choice = MsgBox("Do you want to continue searching for """ & What & """?", _ vbQuestion + vbOKCancel) 'Choice = MsgBox("Do you want to continue searching?", vbQuestion + vbOKCancel) If Choice = vbCancel Then Exit Sub Set Cell = Rng.FindNext(Cell) '----------- If Cell.Address = Addx Then If MsgBox("This is the end of your search. Do you want to continue?", _ vbQuestion + vbOKCancel) = vbCancel then Exit sub Exit Do end if '--------- Loop End If Wks.Visible = State Next Wks
If Not Found Then MsgBox "No matches were found for """ & What & """" End If
Bookmarks