Don't want my TextBox_Find to begin until I'm finished typing

FisherKat

New Member
Joined
Oct 16, 2018
Messages
14
How do you set the TextBox_Find to not begin the VBA search until you have completed typing your keyboard strokes? Mine begins it's search as soon as the first character is typewritten and the search is for over 460,000 cells.

Thank you!
 

FisherKat

New Member
Joined
Oct 16, 2018
Messages
14
Show as your code and we will see.
Here you go....Thank you!

Code:
Dim strSearchAddress As String

Private Sub CommandButton1_Click()

Dim strAddress As String
Dim strSheet As String
Dim strCell As String
Dim l As Long
Dim lLastRow As Long
Const sRESULTS As String = "Results Sheet"

    For l = 0 To ListBox_Results.ListCount
        If ListBox_Results.Selected(l) = True Then
            strAddress = ListBox_Results.List(l, 1)
            strSheet = Replace(Mid(strAddress, 1, InStr(1, strAddress, "!") - 1), "'", "")
            Worksheets(strSheet).Select
            Worksheets(strSheet).Range(strAddress).Select
          
            With Worksheets(sRESULTS)
                lLastRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1

                .Range("A" & lLastRow).Value = Worksheets(strSheet).Range(strAddress).Value
                .Range("B" & lLastRow).Value = "Item Number"
                .Range("C" & lLastRow).Value = "Quantity"
                .Range("D" & lLastRow).Value = "On Hand Stock Location"
                .Range("E" & lLastRow).Value = Now
                .Range("F" & lLastRow).Value = strAddress

            End With
           
            GoTo EndLoop
        End If
    Next l

EndLoop:

End Sub

Private Sub Label1_Click()

End Sub

Private Sub UserForm_Initialize()

Dim ws As Worksheet
Dim lRow As Long
Dim lCol As Long
Dim lMaxRow As Long
Dim lMaxCol As Long

    lMaxRow = 0
    lMaxCol = 0
   
    For Each ws In ActiveWorkbook.Worksheets
        lRow = ws.UsedRange.Cells.Rows.Count
        lCol = ws.UsedRange.Cells.Columns.Count

        If lRow > lMaxRow Then lMaxRow = lRow
        If lCol > lMaxCol Then lMaxCol = lCol
    Next ws
   
    strSearchAddress = Range(Cells(1, 1), Cells(lMaxRow, lMaxCol)).Address

End Sub

Private Sub TextBox_Find_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)


    Call FindAllMatches
   
End Sub

Private Sub Label_ClearFind_Click()

    Me.TextBox_Find.Text = ""
    Me.TextBox_Find.SetFocus
   
End Sub

Sub FindAllMatches()

Dim FindWhat As Variant
Dim FoundCells As Variant
Dim FoundCell As Range
Dim arrResults() As Variant
Dim lFound As Long
Dim lSearchCol As Long
Dim lLastRow As Long
Dim lWS As Long
Dim lCount As Long
Dim ws As Worksheet
Dim lRow As Long
Dim lCol As Long
Dim lMaxRow As Long
Dim lMaxCol As Long
  
    If Len(f_FindAll.TextBox_Find.Value) > 1 Then
       
        FindWhat = f_FindAll.TextBox_Find.Value

        FoundCells = FindAllOnWorksheets(Nothing, Empty, SearchAddress:=strSearchAddress, _
                                FindWhat:=FindWhat, _
                                LookIn:=xlValues, _
                                LookAt:=xlPart, _
                                SearchOrder:=xlByColumns, _
                                MatchCase:=False, _
                                BeginsWith:=vbNullString, _
                                EndsWith:=vbNullString, _
                                BeginEndCompare:=vbTextCompare)

        lCount = 0
        For lWS = LBound(FoundCells) To UBound(FoundCells)
            If Not FoundCells(lWS) Is Nothing Then
                lCount = lCount + FoundCells(lWS).Count
            End If
        Next lWS
       
        If lCount = 0 Then
            ReDim arrResults(1 To 1, 1 To 8)
            arrResults(1, 1) = "No Results"
       
        Else
       
            ReDim arrResults(1 To lCount, 1 To 8)
           
            lFound = 1
            For lWS = LBound(FoundCells) To UBound(FoundCells)
                If Not FoundCells(lWS) Is Nothing Then
                    For Each FoundCell In FoundCells(lWS)
                        arrResults(lFound, 1) = FoundCell.Value
                        arrResults(lFound, 2) = "'" & FoundCell.Parent.Name & "'!" & FoundCell.Address(External:=False)
                        arrResults(lFound, 3) = FoundCell.EntireRow.Cells(3).Value
                        arrResults(lFound, 4) = FoundCell.EntireRow.Cells(4).Value
                        arrResults(lFound, 5) = FoundCell.EntireRow.Cells(5).Value
                        arrResults(lFound, 6) = FoundCell.EntireRow.Cells(6).Value
                        arrResults(lFound, 7) = FoundCell.EntireRow.Cells(7).Value
                        arrResults(lFound, 8) = FoundCell.EntireRow.Cells(8).Value
                       
                        lFound = lFound + 1
                    Next FoundCell
                End If
            Next lWS
        End If
       
        Me.ListBox_Results.List = arrResults
       
    Else
        Me.ListBox_Results.Clear
    End If
       
End Sub

Private Sub ListBox_Results_Click()

Dim strAddress As String
Dim strSheet As String
Dim strCell As String
Dim l As Long

    For l = 0 To ListBox_Results.ListCount
        If ListBox_Results.Selected(l) = True Then
            strAddress = ListBox_Results.List(l, 1)
            strSheet = Replace(Mid(strAddress, 1, InStr(1, strAddress, "!") - 1), "'", "")
            Worksheets(strSheet).Select
            Worksheets(strSheet).Range(strAddress).Select
            GoTo EndLoop
        End If
    Next l

EndLoop:
   
End Sub

Private Sub CommandButton_Close_Click()

    Unload Me
   
End Sub
 
Last edited by a moderator:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
Replace this section of code
VBA Code:
Private Sub TextBox_Find_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)


    Call FindAllMatches
  
End Sub
with
VBA Code:
Private Sub TextBox_Find_AfterUpdate()

    Call FindAllMatches

End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,317
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,082,297
Messages
5,364,370
Members
400,792
Latest member
Dxmiian

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top