+ Reply to Thread
Results 1 to 16 of 16

Userform searching data on another workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Cool Userform searching data on another workbook

    Hi everyone,


    I have created a userform to search data kept in a different workbook. Several problems in hand:

    1) How to get the user form on file FKT.xls to retrieve data from the workbook Data1.xls?

    2) Formating the presentation of data: the column M, where are the results i need to present on the user form are displayed on text line, i need them to be presented as vertical list.

    3) to not be able to close the user form on the X, but using only the Close button, and display message "Please use Close button".

    Thanks everyone,

    VS
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    The data to search is in column N, and the data to present in column M.

    The objective is to search for an account (N) and retrieve the equivalent values (M).

  3. #3
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    Hello sachs_v5
    Try the attached for 1 and 2 to see if it meets these parts of your requirement.
    There is no need for the Clear button the list will clear on a successful find.

    FKT.xlsm

    For part 3 follow this link
    http://www.contextures.com/xlUserForm01.html
    Last edited by barryleajo; 01-20-2013 at 06:56 PM. Reason: Add link
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform searching data on another workbook

    Hi VS

    For Part 3...here's one way...place this code in the UserForm Module
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = vbFormControlMenu Then
            Cancel = True
            MsgBox "Please use the Close button!"
        End If
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi guys,

    @barryleajo & jaslake, many thanks for your prompt solutions. Could you assist in the following:

    1- how to put FKT.xls to open and close the data1.xls file automatically (location of both files C:\FKT\data1.xls). It is not very user friendly to have to open the data1 file first and then the FKT file.

    2- my search field, txtTarget, should search for partial content of the cell and not only exact matches. (cell content = 1030028888T, i wish to search by 28888T for instance)

    3 - how to create a right-click button option on top of the search result (1 line only) "Copy", that only copies the last 10 digits of the search result. (it shows EUR 6987004000 and i want to copy only the 10 numbers using the right-click option "Copy".

    thanks in advance for your help

  6. #6
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    VS
    Can I just check:
    1. how many chars of 'partial content' makes the match on search in col N unique
    2. where would you wish the selected search result to be copied to?
    3. do you really need a RIGHT CLICK selection rather than a conventional left click on the search results list box
    Thanks
    barry
    Last edited by barryleajo; 01-22-2013 at 10:36 AM.

  7. #7
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi barry,

    I have followed a different way. I managed to open the file where data was kept and solved issue #1 of my previous post.

    1) I have now created a 2nd text box to where i copy with double click on lstResults the selected line of the search i made. I need now to make visible on this new text box only the last 10 digits of the search. i.e. result of the search is USD 6984564000 and i just want to view the numbers of the text box. how can i manage this? After the double-click that will export the selected line to the txtbox, i'd like the text to be selected automatically so i can copy it just with ctrl+C instead of having to select the text with mouse.

    2) On the search text box i want to search for partial content of column N, all accounts start with 10300, i do not have the need to put that number, just want to search for the last 5 characters. i.e. 1030028888T, i want to search for 28888T (an expression like contains maybe?)

    3) Recap... I enter 28888T (not mandatory to restrict to 6 characters), i press ENTER or button search (both ways must work), the results go to lstResults, i double-click the line i wish (i.e. USD 6984564000), the last 10 characters go to the text box and are highlighted for selection with CTRL+C shortcut or right-click button option "Copy".

    i guess this will be all i need to be just perfect.

    Regards to all

  8. #8
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    Hi VS
    Thanks for response which I have read very carefully.
    I have attached an update for your consideration.
    You can have a second text box if you wish but it seems like a redundant operation to me.

    The attached:
    1. Opens/closes the data file
    2. Does a partial no. search (in col N) and returns ALL a/c no's to the list box. A search with a blank box clears the list.
    3. Right click on a list box item selects it and automatically copies the last 10 chars to the clipboard and gives a confirmatory message to the user.

    I have added John's code to force use of the Close button - thanks John.
    At the moment this only closes the Userform not the workbook.
    Let me know if this meets your requirement.
    barry

    PS. Need to be careful about managing the various file versions now!

    FKTv3.xlsm

  9. #9
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi barry,

    I have attached the last version of my file. Thanks for your guidance and codes provided to reach the result i have adapted. Almost there, can you assist with the following queries:

    1) users must enter a 6 digit (5 numbers + 1 letter) to perform the search with sucess. Else a popup message "Please enter valid format account".

    2) how to put tags appearing when the mouse is on top of the field? lets say i wish to have a tag ("righ-click to copy the account selected") whenever the mouse scroll is on top of the list box Results.

    3) as soon the correct format to search is inputed (i.e. 28888T, we can either press ENTER and the search begans auto, or use the "SEARCH" button as the code already working with. any idea for this?

    once again thanks a lot barry
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    OK VS this should do it
    Your file with further amends attached - change your file names/locations
    We could consider a "Search Anyway?" enhancement to txtTarget for wildcard type searches?

    FKT 240113.xlsm

  11. #11
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi,


    While running pre-production tests some issues came along:

    1) I need to search column N when column B is equal to "Open", where to input this rule?

    2) when listbox as many results, for instance for account 28888T, when the mouse pointer is on top of the bottom accounts, like USD or TRY, the account choosen will be the one below the one i wish. I guess this is related with the listbox results being too many, but how to solve?

    for now the "search anyway" wont be necessary as i need exact results.

    Regards,

    VS

  12. #12
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    Hi VS

    2. I think this issue has been caused by you changing the font size in the lstResults ListBox. I hadn't noticed but all of the selections were one row out, not just the last one. The attached file "corrects" this issue. It's to do with position calculations arising out of your requirement for right-click selection.

    1. I am unsure about your new requirement in point 1. The data file I am using has nothing entered in col B. Please upload an updated test data file with col B populated.
    To be clear you only want search results where txtTarget.Value is found in col N AND col B.Value in that same row = "Open"

    Previous comments apply about "version control". The attached is an update on 'FKT 240113'

    barry

    FKT 290113.xlsm

  13. #13
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi barry,

    I have not changed the font size in lstResults lisbox, still Tahoma bold size 10. in the comand line the size is 1.2 like originally you gave me, now you changed it to 1.5 and is getting worse. I have found a tricky way, i sized my listbox to 123,2 height, this way i only see 10 lines and use the vertical scrollbar to go down. This way the result i right-click is always the one copied to clipboard.

    About the requirement on point 1, on the data1.xls there is no content on column B, but the definitive data file has column B with "Open" or "Closed". I wish to search results on column N with column B = "Open", same row.

    I now update my last version of both my files.

    VSFKT.xlsFondsliste.xls

  14. #14
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    Hi VS
    I was working on a version where lstResults was Tahoma regular size 8pt(?).
    Good lesson for keeping updates in sync and at least we seem to have found the reason/fix.

    Many thanks for the updated files.
    Try the attached - your latest version with amends.

    FKT 300113.xls

  15. #15
    Registered User
    Join Date
    08-28-2012
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Userform searching data on another workbook

    Hi barry,

    Is working fine and no new issues found so far. Many thanks for all your support and assistance.

    Regards my friend.

    VS

  16. #16
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Userform searching data on another workbook

    That's great.
    Perhaps you would mark your thread as SOLVED

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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