Hi folks,
This search looks through the Range C14:C125. It always starts looking from the row where the activecell is. That way, if it finds one match, pressing the find button again looks for the next match. The problem is, once the search reaches the end of the range (C125) I can't seem to get it to go back up to the top and look again starting at C14.
The ultimate goal is to push the find button, have it find a match and select the cell. Pushing the find button again finds the next one down in the range, and then selects it (if there are more than one instance of the same entry...) and, if while looking it gets to the the bottom of the range, C125, it heads back up to C14 and continues from there.
Let me know if I'm not being clear!!
Thanks again in advance.
This search looks through the Range C14:C125. It always starts looking from the row where the activecell is. That way, if it finds one match, pressing the find button again looks for the next match. The problem is, once the search reaches the end of the range (C125) I can't seem to get it to go back up to the top and look again starting at C14.
The ultimate goal is to push the find button, have it find a match and select the cell. Pushing the find button again finds the next one down in the range, and then selects it (if there are more than one instance of the same entry...) and, if while looking it gets to the the bottom of the range, C125, it heads back up to C14 and continues from there.
Let me know if I'm not being clear!!
Thanks again in advance.
Code:
[COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] Search_Unit_Click()
[COLOR=darkgreen]'Check if entry is blank[/COLOR]
[COLOR=blue]If[/COLOR] Unit_Textbox.Text = vbNullString [COLOR=blue]Then[/COLOR]
MsgBox " Please enter a valid 4 digit unit number. ", vbOKOnly + vbCritical, "Enter Unit"
[COLOR=blue]Goto[/COLOR] ProcedureEnd
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
[COLOR=darkgreen]'Identify where to search[/COLOR]
[COLOR=blue]Set[/COLOR] SearchRange = Worksheets("Ottawa Roster").Range("C14:C125")
[COLOR=darkgreen]'Search Roster and set UnitFound As Address[/COLOR]
Search:
[COLOR=blue]Set[/COLOR] UnitFound = SearchRange.Find(What:=(Unit_Textbox.Text), After:=Worksheets("Ottawa Roster").Range("C" & ActiveCell.Row))
[COLOR=darkgreen]'If nothing was found[/COLOR]
[COLOR=blue]If[/COLOR] UnitFound [COLOR=blue]Is[/COLOR] [COLOR=blue]Nothing[/COLOR] [COLOR=blue]Then[/COLOR]
MsgBox Unit_Textbox & " was not found as an active unit. ", vbOKOnly + vbExclamation, "Unit Not Found"
[COLOR=blue]Goto[/COLOR] ProcedureEnd
[COLOR=darkgreen]'If unit is End of Shift - Ignore and continue search[/COLOR]
[COLOR=blue]ElseIf[/COLOR] Worksheets("Ottawa Roster").Range("B" & UnitFound.Row) = "EOS" [COLOR=blue]Then[/COLOR]
Worksheets("Ottawa Roster").Range("C" & UnitFound.Row).Select
[COLOR=blue]Goto[/COLOR] Search
[COLOR=darkgreen]'Select an active unit (not end of shift)[/COLOR]
Else: Worksheets("Ottawa Roster").Range("C" & UnitFound.Row).Select
[COLOR=blue]Goto[/COLOR] ProcedureEnd
[COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
Unload Roster_Userform
Roster_Userform.Show
ProcedureEnd:
[COLOR=blue]On Error Goto[/COLOR] 0
Exit [COLOR=blue]Sub[/COLOR]
[COLOR=blue]End Sub[/COLOR]