+ Reply to Thread
Results 1 to 9 of 9

Userform; search/match two textboxes and then update that row

  1. #1
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Userform; search/match two textboxes and then update that row

    I have a userform that does two things, first it allows me to enter new records if I click a "new record" command button, and then it has an "update record" command button that searches all records (column B) and then updates that row with new information.
    When I originally wrote the program I only wanted to search column B, which worked great, but as I worked with the outside program I learned I need to search both column B and column F, and then update which ever row is found. Here is my code that I originally used to search column B, I cannot figure out how to add F to it.

    Please Login or Register  to view this content.
    my first thought was to set a rng2 to find textbox8.value in range F:F and create a loop between rng1 to rng2, but i haven't been able to teach myself that.
    Attached Files Attached Files
    Last edited by ckaten; 05-24-2018 at 11:14 PM. Reason: add workbook for visual

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Userform; search/match two textboxes and then update that row

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Userform; search/match two textboxes and then update that row

    The code is your file is not the same as the code you pasted above. I am not sure which one to edit, so I'll use the code pasted above.

    Which one has priority, finding TextBox5 in column B, or finding TextBox8 in column F? I am going to assume you want to check TextBox5 first.
    Please Login or Register  to view this content.
    I fixed the indentation of your code, also.

    Also, I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.
    Last edited by 6StringJazzer; 05-25-2018 at 08:39 AM. Reason: fixed logic problem in code
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Re: Userform; search/match two textboxes and then update that row

    6stringJazzeryes I tried to pare down the actual code in the paste box just so you did have 100 lines of stuff that won't change with the code to read through. I hope it wasn't too confusing.

    I entered your help and it works good if there is only one entry in column B. For example if B2 is the only cell in B:B that has a value of 5 and F2 is the only cell with a value of 5, it will update row 2. if B2 and B10 both have a value of 5 the program stops and does not continue searching F:F.


    Second, column F is a string variable, and as it the code does not recognize string. Values for F:F could be things like "Happy3" "treeguys24" "aaa" or "123." This is where it would be easier to define it as a variable and then set that variable to string? do I just set textbox8 to string? For now I just changed:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    and it seems to work.
    Last edited by ckaten; 06-02-2018 at 02:14 PM.

  5. #5
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Re: Userform; search/match two textboxes and then update that row

    thank you for your help, I have not used the search1Col procedure before, when I try it, it errors on

    Please Login or Register  to view this content.
    Program is expecting byval to be an expression? I am researching a fix for right now.

  6. #6
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Re: Userform; search/match two textboxes and then update that row

    Quote Originally Posted by ckaten View Post
    yes I tried to pare down the actual code in the paste box just so you did have 100 lines of stuff that won't change with the code to read through. I hope it wasn't too confusing.

    I entered your help and it works good if there is only one entry in column B. For example if B2 is the only cell in B:B that has a value of 5 and F2 is the only cell with a value of 5, it will update row 2. if B2 and B10 both have a value of 5 the program stops and does not continue searching F:F.
    OK I figured out it does matter which one I searched first. I rearranged to search column F first because in the real world application for this program column F will be unique more often than not. this however will not help when F is no unique because it will again stop after finding the first condition and not continue to the second one.

    Side note, all I did was change the columns around but all my cell values got shifted 5 columns to the right, is that normal?

  7. #7
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Re: Userform; search/match two textboxes and then update that row

    it looks like you forgot a "sub" in

    Please Login or Register  to view this content.

    which fixed the expression issue, but I am not understanding the code at all. is there anyway to walk through it? My biggest questions are 1) we have 2 Subs, why? 2) What does the "1" in
    Please Login or Register  to view this content.
    do? And 3) Where do we match column F in this code?


    Thank you.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Userform; search/match two textboxes and then update that row

    ckaten, you have answers from two different people posted at almost the same time. Can you clarify who you are responding to?

  9. #9
    Registered User
    Join Date
    05-24-2018
    Location
    miami, fl
    MS-Off Ver
    ms office 365
    Posts
    6

    Re: Userform; search/match two textboxes and then update that row

    Post 5/28/2018 at 2:51 and yesterday at 11:12 was for you 6stringjazzer

+ 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. Search row number match 2 textboxes criteria
    By impresxy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-17-2017, 07:33 AM
  2. [SOLVED] Search, find, match-populate textboxes
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-04-2015, 02:36 AM
  3. Search worksheet for data in multiple textboxes in userform and display in another workshe
    By SierraKilo78 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-23-2013, 09:59 AM
  4. Userform populate listbox with search from multiple textboxes
    By chendysworld in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2012, 11:12 AM
  5. userform - update textboxes (INDIRECT)
    By fredpox in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2010, 07:04 AM
  6. Update Userform textboxes on the fly
    By jaslake in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-13-2009, 05:20 PM
  7. Capture worksheet switching inside userform and update textboxes to new sheet
    By RockiesMan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-21-2007, 05:10 PM

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