+ Reply to Thread
Results 1 to 43 of 43

Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemObject

  1. #1
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemObject

    I have been able to achieve this many different ways, but my methods become obsolete if there are too many rows.
    My first attempt was something like this:
    Please Login or Register  to view this content.
    This worked fine for smaller groups of data, but with 150,000 rows, this code brings my computer to its knees. I also tried using .Find, and it got even slower.. My final attempts were with Scripting.Dictionary and FileSystemObject, seemed as if they would have worked much better, but I couldn't quite get either to work correctly.

    So if anyone can code a search that can look through > 200,000 rows
    -Find a match,
    -Select the first blank row on Results Sheet,
    -Return the entire row of corresponding data from sheet1,
    -Skip a column, and continue adding the entire row of corresponding data from sheet2 (so that everything is on the same row)
    -repeat for all occurrences of all strings in ColumnA of a list sheet
    it would be greatly appreciated!

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

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Try this...

    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
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    That's really close, looks like matched rows from sheet2 are being returned, but nothing from sheet1

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Please attach a sample

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I wrote the attached to a question on this forum. The question and format of the answer appear to be very similar.
    Try it

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I wrote the attached to a question on this forum. The question and format of the answer appear to be very similar to your request.
    Try it
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Sorry, Should have done that from the start:
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    That one is close too.. Maybe the code i have been using can explain it better than i can word it:
    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Have you tried my code?

  10. #10
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I have, but it's a bit different. Basically it's :
    for each x in ListSh.Col-B, find every occurrence (y) of ListSh.Col-B.Offset(0,-1) _
    in DataSh.Col-A..

    So the final results should show 4 results for "boys.":
    2 boys ("A & B") who are both in ("Class1") and
    2 boys ("A & B") who are both in ("Class2")


    .......LIST SHEET...................DATA SHEET............
    col(A)--col(B)------col(C)...||--col(A)-----col(B)----col(C)
    boys----------A--------Blah....||...boys---CLASS-1-----FOO
    boys----------B--------Blah....||...boys---CLASS-2-----FOO
    .girls----------C--------Blah....||....girls---CLASS-3-----FOO
    .girls----------D--------Blah....||....girls---CLASS-4-----FOO
    .girls----------E--------Blah....||


    This would return the following to results:

    RESULTS SHEET

    boys-----A-----Blah-----boys---CLASS-1---Blah
    boys-----A-----Blah-----boys---CLASS-2---Blah
    |
    boys-----B-----Blah-----boys---CLASS-1---Blah
    boys-----B-----Blah-----boys---CLASS-2---Blah
    |
    .girls-----C-----Blah-----girls CLASS-3---FOO
    .girls-----C-----Blah-----girls CLASS-4---FOO
    |
    .girls-----D-----Blah-----girls CLASS-3---FOO
    .girls-----D-----Blah-----girls CLASS-4---FOO
    |
    .girls-----E-----Blah-----girls CLASS-3---FOO
    .girls-----E-----Blah-----girls CLASS-4---FOO
    Last edited by downtown1933; 09-29-2013 at 05:42 AM.

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Hi downtown1933,
    try it
    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    downtown1933,
    My code works on a single row as per your description, but Nilem came up with a better and accurate code.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    This should do how you wanted,
    Attached Files Attached Files
    Last edited by jindon; 09-29-2013 at 06:42 AM.

  14. #14
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    nilem & jindon, both codes worked perfectly on the sample data, but when tested on my actual data, Excel froze up and restarted itself... I cant seem to find anything that can handle processing that many rows!?

  15. #15
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    My actual data would be about the same as the sample data, only differences really being that the Actual ListSh has about 1700 Rows, and the Actual DataSh has about 7,000 Rows.. I know that in the end, when matched correctly there should be well over 100,000 on the results sheet... It just seems like anything i try brings my computer to its knees

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    downtows1933,
    100k is a massive data, but I would not expect my PC to freeze. Yes, the code may take a couple of minutes to run, but not to freeze.
    What is your memory gig?

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Try this then
    Attached Files Attached Files
    Last edited by jindon; 09-29-2013 at 08:55 PM. Reason: File replaced

  18. #18
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Got a Type Mis Match Here:

    n = n + UBound(.Item(a(i, 1)), 2) + 1

  19. #19
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Not sure how would i check?

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Are the data layouts the same?

    The data should start from A1.

  21. #21
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I got it running, but its been going for 9 minutes now un-responsive? Im not sure if it's frozen or still running?

  22. #22
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Hi downtown1933,
    could you upload your real file to the file sharing and show the link here?

  23. #23
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    downtown1933

    This took 26.6250 sec for 25727 rows in Sample List.
    So, it may take much longer if you have many rows in both sheets.
    Please Login or Register  to view this content.

  24. #24
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    or:
    Please Login or Register  to view this content.



  25. #25
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    26 Seconds!? Is it something I'm doing wrong? I tried running yours jindon first thing this morning.. It has been going for about 6 minutes now..Right now I've got about 1500-1600 rows in my list, and 5540 Rows in my Data.....


    Ok so while I was writing this, it stopped running after about 6 1/2 minutes with an error on this line:
    " Sheets("sample results").Cells(x, 1).Resize(n, UBound(b, 2)).Value = b "

  26. #26
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    snb Yours ran pretty quick, but not quite everything was returned.

  27. #27
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    26 sec is made under

    25272 rows in Sample list
    39 rows in Sample Data
    End up 172460 rows in result.

    1500 * 5540 = 8310000 (maximum possibility)

    It easily exceeds the row limit of 1048576.
    Exceeds the row limits in Excel.

  28. #28
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I suspect your data are loaded from an application, such as SAP, or oracle. In other words, you data are not originally created in excel, rather they are exported in to excel from external application. If my assumption is right, even 20k rows will crash excel.
    That is my experience any way. You need to convert these data in VALUES ONLY FIRST before you work on them.

  29. #29
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    jindon,
    i tried your "book2 with code2" again. I added values to Column H in both sheets and it started running..
    I still got the error in line 34 here: " n = n + UBound(.Item(a(i, 1)), 2) + 1 "

    However, There were about 25000 rows that were still sent to the results sheet prior to the error?

  30. #30
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    AB33, are you saying to just copy/paste as values before running? And just for future reference, why would pasting everything as values make a difference?

  31. #31
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I do not know the reason, perhaps more experience people can suggest possible reasons.
    I was answering a thread, similar question to this. The OP had e-mailed me his spread sheet. He had about 20k rows, but when I run the code, it kept crashing my PC- Infact 3 times. I thought I lost my laptop. My laptop was making lots of noise when I run the code. My laptop is prey new. 8 Gig memory.

    I copied the sheets and converted the data in VALUES ONLY, deleted the source sheet. Boy, the code run in 5 seconds.
    I had similar other experience in this site after the first incidence.
    If I run a code and PC starts to make noise, I know these data are imported one. This is just my experience in this site.
    As I said, I have no idea what causes this behaviour, but I suspect these data may have unseen dirty data.

  32. #32
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Quote Originally Posted by downtown1933 View Post
    jindon,
    i tried your "book2 with code2" again. I added values to Column H in both sheets and it started running..
    I still got the error in line 34 here: " n = n + UBound(.Item(a(i, 1)), 2) + 1 "

    However, There were about 25000 rows that were still sent to the results sheet prior to the error?
    I have just tested the file with 25272 rows of data with Col.H added to both sheet.

    It run without error.

    Make sure data starts from A1 in both sheet.

  33. #33
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    jindon,

    To add to the mystery of this error i keep getting; I pasted a smaller sample of my data to your "book2 with code2" and ran it again. This time it executed perfectly, with no error?

    Every time I run it, I remove any blank lines, and sort Col-A values from smallest to largest. The only variable which has changed here is that i used a smaller number of rows. Could it be the size?

  34. #34
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    I think we are talking about different codes.

    I'm running the code in my post #23
    that is
    Please Login or Register  to view this content.

  35. #35
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    It looks like the error goes away if i remove all blanks, and remove all Col-A values that have letters & Numbers.. (ie: "API1000023456")
    Would that make sense? Should the cell value have any impact on the results?

  36. #36
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Blanks are no good, but the "API1000023456" should not affect the result.

    Need to see the actual data type anyway if possible.

    P.S.
    Past midnight, so I will see you tomorrow if any problem left.
    Last edited by jindon; 09-30-2013 at 11:59 AM.

  37. #37
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    That's crazy because I have come across similar issues. I don't recall what exactly it was that I was trying to accomplish, but my PC has crashed while trying to run very simple code. I don't remember how big the file was, but I do remember the noises it made right before doing so...

    Do you remember where your data came from before you put it in excel?

  38. #38
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Quote Originally Posted by jindon View Post
    Blanks are no good, but the "API1000023456" should not affect the result.

    Need to see the actual data type anyway if possible.

    P.S.
    Past midnight, so I will see you tomorrow if any problem left.



    Thanks jindon! There was some special character on the end of some of my Col-A values.. I took those out and it works Great. I also added a timer, With a list sheet containing about 1600 values, being matched to Data Sheet with about 6,000 values, it pulls almost 170,000 rows to results sheet, in 6.58 minutes. This is the code that did it courtesy of jindon:

    Please Login or Register  to view this content.

  39. #39
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    That's good to hear.

    That's all I can do for you.

    If the code solved your problem, please mark this thread as "Solved"

  40. #40
    Registered User
    Join Date
    02-02-2013
    Location
    texas
    MS-Off Ver
    Excel 2003/2010
    Posts
    59

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    jindon, one more thing, would you mind commenting your code? I'm still a bit new to the Scripting.Dictionary and I want to understand what exactly you just did. Thanks again.

  41. #41
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    1)
    Please Login or Register  to view this content.
    2)
    Please Login or Register  to view this content.
    Help?

  42. #42
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    "There was some special character on the end of some of my Col-A values.. I took those out and it works Great."
    That was my point!
    I believe copy and paste VALUES ONLY get rid of these characters.
    Last edited by AB33; 10-01-2013 at 03:42 AM.

  43. #43
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Trying to search for list of strings using Arrays,Scripting Dictionary or FileSystemOb

    Dear All,

    While I see the thread has been solved I wanted to have a go at this 'problem' as well. I have gone the recordset route joining the data on the two input worksheets on the key column and dumping the contents of the recordset onto a third worksheet. Granted it does not have the blank rows in between but it did manage to output 600,000 result rows in under 8 seconds, and the code looks quite clean.

    If anybody is interested:

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

+ 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. Object - Scripting.Dictionary
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2013, 06:00 AM
  2. [SOLVED] Scripting Dictionary
    By thisisgerald in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-18-2012, 01:30 PM
  3. [SOLVED] Scripting Dictionary help
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2012, 08:22 AM
  4. Scripting.FileSystemObject gives Permission denied
    By CrazyFileMaker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-16-2011, 02:29 PM
  5. [SOLVED] Scripting.FileSystemObject
    By Leif Rasmussen in forum Excel General
    Replies: 1
    Last Post: 01-12-2005, 08:06 PM

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