+ Reply to Thread
Results 1 to 3 of 3

Search & Display Userform Not Returning Text and Error Code

  1. #1
    Registered User
    Join Date
    07-29-2020
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    4

    Search & Display Userform Not Returning Text and Error Code

    Hi,

    I'm attempting to create a userform that allows search and display. I've used the below code in the past and have worked for all worksheets w/I a workbook for some reason won't work for this one, please help. When it was included in the large workbook, I did not receive an error message BUT when I enter the "Last Name" in the first text box of the form, it would not render any values in the remaining boxes but remained blank.

    I decided to copy this worksheet to create a new book with only this one sheet included and recreated the form and code and now I'm getting an error message "Object not found".

    Can someone please help? I don't think there is anything wrong with the code because works with other sheets is there something wrong with this sheet? I've also attached a copy of the workbook and macro

    Private Sub CommandButton1_Click()

    Dim acct_no_1 As String
    acct_no_1 = Trim(TextBox1.Text)
    Lastrow = Worksheets("GOVs & Operators").Cells(Rows.Count, 1).End(xlUp).Row

    For i = 2 To Lastrow
    If Worksheets("GOVs & Operators").Cells(i, 1).Value = last_name Then
    TextBox2.Text = Worksheets("GOVs & Operators").Cells(i, 2).Value
    TextBox3.Text = Worksheets("GOVs & Operators").Cells(i, 3).Value
    TextBox4.Text = Worksheets("GOVs & Operators").Cells(i, 4).Value
    TextBox5.Text = Worksheets("GOVs & Operators").Cells(i, 5).Value
    TextBox6.Text = Worksheets("GOVs & Operators").Cells(i, 6).Value
    End If
    Next

    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Search & Display Userform Not Returning Text and Error Code

    Hi and welcome to the forum. There is quite a bit wrong with the code. It couldn't possibly work as it is.

    1.) Your example workbook userform has no textboxes. The code refers to six different textboxes.

    2.) You enter the account number in TextBox1, but you try to match the last name. The code has no defined last_name.
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-29-2020
    Location
    Dallas, TX
    MS-Off Ver
    365
    Posts
    4

    Re: Search & Display Userform Not Returning Text and Error Code

    I've updated the code see below and attached. I'm now getting a "run time error 9" saying "subscript error" can you please help?

    Private Sub SearchDisplay_Click()

    Dim acct_no_1 As String
    acct_no_1 = Trim(TextBox1.Text)
    Lastrow = Worksheets("GOVs & Operators").Cells(Rows.Count, 1).End(xlUp).Row

    For i = 2 To Lastrow
    If Worksheets("GOVs & Operators)").Cells(i, 1).Value = acct_no_1 Then
    TextBox2.Text = Worksheets("GOVs & Operators").Cells(i, 2).Value
    TextBox3.Text = Worksheets("GOVs & Operators").Cells(i, 3).Value
    TextBox4.Text = Worksheets("GOVs & Operators").Cells(i, 4).Value
    TextBox5.Text = Worksheets("GOVs & Operators").Cells(i, 5).Value
    TextBox6.Text = Worksheets("GOVs & Operators").Cells(i, 6).Value
    End If
    Next

    End Sub
    Attached Files Attached Files

+ 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. [SOLVED] Code to display text & code in a combo list, but display only code when selected
    By kdestef1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2019, 06:07 PM
  2. Replies: 2
    Last Post: 05-24-2016, 05:27 AM
  3. [SOLVED] Userform to search worksheet and display data back to the userform
    By zip247 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2015, 05:46 AM
  4. how to add a search option in userform and display it in text box
    By ruveenck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2014, 04:33 AM
  5. Userform find/search text, can i make it's short code ?
    By johnreid7477 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-03-2014, 04:28 PM
  6. UserForm help - display list of open workbooks except workbook userform code is in
    By kensweep in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2014, 12:26 PM
  7. Help: Search data in worksheet and display the data in userform text boxes
    By RAB7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2013, 05:37 AM

Tags for this Thread

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