Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi All, good afternoon, i have the code below where i have a search userform whcih is located on same page as to where the data is, i want to move the search button onto my home page and then find the data, but i dont know how to add where it needs to search for example i want it to find the data in 'Thisworkbook Sheet "FTE Search", can you help me please with the code? and for when it returns the data found for it to just bring it up in the userform and not to goto the page it is on?
Code:
Sub FindAllMatches()
Dim SearchRange As Range
Dim FindWhat As Variant
Dim FoundCells As Range
Dim FoundCell As Range
Dim arrResults() As Variant
Dim lFound As Long
Dim lSearchCol As Long
Dim lLastRow As Long
If Len(UserForm3.TextBox_Find.Value) > 1 Then
Set SearchRange = ActiveSheet.UsedRange.Cells
FindWhat = UserForm3.TextBox_Find.Value
Set FoundCells = FindAll(SearchRange:=SearchRange, _
FindWhat:=FindWhat, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
MatchCase:=False, _
BeginsWith:=vbNullString, _
EndsWith:=vbNullString, _
BeginEndCompare:=vbTextCompare)
If FoundCells Is Nothing Then
ReDim arrResults(1 To 1, 1 To 2)
arrResults(1, 1) = "No Results"
Else
ReDim arrResults(1 To FoundCells.Count, 1 To 10)
lFound = 1
For Each FoundCell In FoundCells
arrResults(lFound, 1) = FoundCell.Value
arrResults(lFound, 3) = FoundCell.Value
arrResults(lFound, 4) = FoundCell.Value
arrResults(lFound, 5) = FoundCell.Value
arrResults(lFound, 6) = FoundCell.Value
arrResults(lFound, 7) = FoundCell.Value
arrResults(lFound, 8) = FoundCell.Value
arrResults(lFound, 9) = FoundCell.Value
arrResults(lFound, 10) = FoundCell.Value
arrResults(lFound, 2) = FoundCell.Address
lFound = lFound + 1
Next FoundCell
End If
Me.ListBox_Results.List = arrResults
Else
Me.ListBox_Results.Clear
End If
End Sub