+ Reply to Thread
Results 1 to 5 of 5

Textbox VBA code if values not found

  1. #1
    Registered User
    Join Date
    08-10-2016
    Location
    Riyadh
    MS-Off Ver
    2010
    Posts
    8

    Textbox VBA code if values not found

    hi,

    the excel was crashing when the values i type in the textbox are not found. kindly please provide an additional code to avoid it from crashing when the values are not found.


    txtSearch = the textbox that will initiate the searching in the listbox while typing.
    lstbox = the listbox that contains the data with 7 columns

    Private Sub txtSearch_Change()
    Dim i As Long
    Dim c As Long
    Dim Str As String


    Str = Me.txtSearch.Text
    For i = 0 To Me.lstbox.ListCount - 1
    For c = 0 To Me.lstbox.ColumnCount - 1
    If LCase(Me.lstbox.List(i, c)) Like LCase(Str) & "*" Then
    Me.lstbox.ListIndex = i
    Exit Sub
    End If
    Next c
    Next i


    End Sub

    Thanks & Regards,
    Attached Files Attached Files

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: Textbox VBA code if values not found

    You are downloading 1048576 rows in the listbox. To go through all the rows in the search have a lot of time. It is necessary to change the method of filling a listbox.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  3. #3
    Registered User
    Join Date
    08-10-2016
    Location
    Riyadh
    MS-Off Ver
    2010
    Posts
    8

    Re: Textbox VBA code if values not found

    Thank you sir, do you have any suggestion on how the textbox will search within the listbox without crashing? or maybe a new code with the same function?

    Quote Originally Posted by kalbasiatka View Post
    You are downloading 1048576 rows in the listbox. To go through all the rows in the search have a lot of time. It is necessary to change the method of filling a listbox.

  4. #4
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: Textbox VBA code if values not found

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-10-2016
    Location
    Riyadh
    MS-Off Ver
    2010
    Posts
    8

    Re: Textbox VBA code if values not found

    Thanks a lot sir!

    thread [solved]

    Best Regards,

    Quote Originally Posted by kalbasiatka View Post
    Please Login or Register  to view this content.
    Last edited by Eon25; 08-13-2016 at 10:21 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code to return 2 vlookup values into 1 textbox on userform
    By gemnnsw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2016, 10:52 AM
  2. VBA code to lookup cell value on another sheet and paste old values once found help
    By Zimmerman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-20-2016, 11:18 PM
  3. replace code/id values with a name found in a list
    By ebbo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2015, 10:25 AM
  4. Check for values in a table and if found add value found in column to left to list
    By robhargreaves in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-07-2013, 02:57 PM
  5. VB code to find recurring values and return x columns and x rows from found
    By TravisJB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-07-2013, 12:28 PM
  6. VBA code to Subtract values in Column F with Column E if found non-blank
    By hydz1213 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2013, 04:34 AM
  7. VBA - Macro Code to copy textbox text to another worksheet textbox
    By nitram lowm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2013, 08:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1