+ Reply to Thread
Results 1 to 33 of 33

Get matching values using ADO from closed CSV file

  1. #1
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Get matching values using ADO from closed CSV file

    Hi everyone,

    I have attached 2 sample files. I'm trying to get a kind of Vlookup from data that is in a more than 50 MB CSV file (comma delimeted).
    I want to lookup values in column A of "LookUpResults.xlsx" that match values in column A of "Origin.csv". For each matching row, put in
    column B values from column B, in C values from C, in D values from D.

    I've been trying some ADO codes in order to test but doesn't show any value.

    Some of the codes I've been testing without success is:
    (source: http://technet.microsoft.com/en-us/l.../ee692882.aspx)

    Please Login or Register  to view this content.
    May somebody help me to get this working?

    * The Origin.csv files doesn't have headers.

    Many thanks in advance.

    Regards
    Attached Files Attached Files
    Last edited by cgkmal; 09-29-2011 at 03:02 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    I don't see where your code makes any attempt to read from the CSV file?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Quote Originally Posted by romperstomper View Post
    I don't see where your code makes any attempt to read from the CSV file?
    Hi romperstomper,

    I put the code almost as a reference of what I think could be the way, using ADO, but I'm a beginner in that area.

    I was hoping to understand how that example works and then try to change to a csv, but even that example not seem to show the output as they say.
    In my case I think the middle part of the code would be something like:
    Please Login or Register  to view this content.
    The part in red X=Y should be values in column A of Results.xlsx that are equal to values in A of Origing.csv. I don't know how would be the syntax here and how to retrieve values in other columns for matching rows.

    Like a start I tried following exactly with file in example and didn't work for me, actually my computer hanged when the "Do until EOF loop" was executed.

    Maybe you can help me to get the desired result.

    Many thanks in advance.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Basically:
    Please Login or Register  to view this content.
    assuming the lookup value is text.

  5. #5
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Thanks in trying to help me.

    The value to lookup should be all values in column A of Results.xlsx file. I don't know if a for loop as below or how to lookup for each value within the closed csv file(Origing.csv).
    Please Login or Register  to view this content.
    and once a value is match, how to pull values from other columns in the same row of Origing.csv into corresponding row of the value matched in in desired column in Results.xlsx?

    Many thanks for help so far.

    Regards.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Please Login or Register  to view this content.
    for example.

  7. #7
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    I've run the macro as follow and doesn't seem to do anything
    Please Login or Register  to view this content.
    What could be the problem?

    Thanks for help so far.

    Regards

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    I'd guess no matches. Try this version which will output something either way:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    The same result. where is supposed to appear the pulled values? in active workbook right?

    If you see the attached files it must be 10 matches between result.xlsx and Origin.cvs.

    I'm confused why is not showing anything.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    I overlooked the fact that you did not use my connection string:
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    I added that and the same result, nothing appears in my active workbook.

    and if I remove the error hanling line at the beginning, I receive error in this line.
    Please Login or Register  to view this content.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    I changed the code and ran it on your files and it worked perfectly.

  13. #13
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Ok, that is a good sign.

    Do I need to have enabled some library or something?

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    No, as it's all late bound. What error do you get?

  15. #15
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    It´s working now!!!. The problem was I had the Origin.csv file open.

    Now maybe you could help me with these last 2 questions.

    1-) If I want to copy values from columns into different columns
    example: F2 of Origing to be copied in Col5, F3 of Origing to be copied in Col7 etc. How could I do this?

    2-) After the found values have been copied in order desired, how to delete in Origing.csv those rows that are not present in Result.xlsx?

    Many thanks again a lot Romperstomper.

  16. #16
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    If you want them in random places, you'll have to do them individually:
    Please Login or Register  to view this content.
    for example.
    To delete, you will have to open the file in Excel and loop through the rows.

  17. #17
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    It works, it works, it works!!!!

    Only the deletion part is missing. The problem is I don't want to open the file
    because it has more than 50MB in size. Is not possible to delete the rows without open the file with ADO or other procedure?

  18. #18
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    No. What you could do is read all the matching data in, then just create a new file with that data.

  19. #19
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Ok, I think I understand the idea, I'll try your suggestion.

    Maaaaaany many thanks for your patience and kindly help romperstomper, you have help me a lot!!! and I learned a lot either!!!.

    Best regards

  20. #20
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Glad to help.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  21. #21
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    I'm satisfied with the help received, the code works with ADO works and I'll mark as solved, but I'm not sure if I need to open a new question regarding the issue I describe below.

    The only thing is that when I tried to run the macro and the closed file is like 4 MB in size (10,000 lines) execution time is 50 seconds, but when closed file is larger as 50 MB in size, my computer hangs.

    So, is there another option using VBA within Excel, to get the same result in a faster way, without affecting too much computer resources?


    Thanks again.

  22. #22
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Ah yes - I should have realised that with a csv file it will be much faster to open a recordset with all data once at the start and then filter it:
    Please Login or Register  to view this content.
    for example.

  23. #23
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Hi romperstomper,

    Thanks for your help again.

    I've tried the new version and in this line:
    Please Login or Register  to view this content.
    I get the following error:
    -------------------------------------------------------------------------
    Runtime error "3265"

    Item cannot be found in the collection corresponding to the requested name or ordinal.

    -------------------------------------------------------------------------
    and when I add a "On error Resume Next" as follow
    Please Login or Register  to view this content.
    Only copies the value from first row within "big data.csv" even when there isn't a match. I mean, the value copied from
    recordset is no present in colA in result.xlsx. It seems, the error force the recordset to store only first row even when is not a match.

    Hope I get some help in how to solve this issue.

    Many thanks so far.

    Regards.

  24. #24
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Don't add On Error Resume Next. Did you alter the SQL statement to include the first field, as in the code I posted?

  25. #25
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Hi romperstomper,

    Yes, I've used entirely your new code.

    I use this:
    Please Login or Register  to view this content.
    in combination of this:
    Please Login or Register  to view this content.
    I'm not sure, but it seems when a value in cells(i,1) is not in [F1] the problem appear. I don't know because happens with the first value. After that I can't continue.

    Maybe you know what could be the problem.

    Thanks a lot for your help.

    Regards

  26. #26
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    Is your file called Big Data.csv?

  27. #27
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    No, it has a different name, but I changed it properly. Even I tried to use a string variable instead of the
    [Bid Data.csv] but I got an error, then I only changed to [Source.csv]. I think it could be other problem.

  28. #28
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    It would be helpful if you post the actual code you are running so I can verify any changes made.
    If you change the first line in the workbook so that it matches a line in the csv file, does it work?

  29. #29
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Sorry I looked in depth and I realized that I replaced everything except one thing,

    The correct code you provided contains [F1] in select line and I had missing
    didnt have [F1] in my code, I had this:
    Please Login or Register  to view this content.
    when the correct is:
    Please Login or Register  to view this content.
    Well, knowing that issue I could test the macro but I found that the execution is very slow. When the line "objRecordset.Filter=..." is executed
    it took like 10 seconds to pass to the next line of code. It seems that needs much time when filters a value within the Recordset.

    After 5 minutes only 10 found lines were printed. I had to stop Excel because almost hangs.

  30. #30
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    And that's why I asked for the actual code.

    It seems you need a proper database. In my tests with a 1m+ row csv file it was pretty fast, but the search values were near the beginning which may have helped.

  31. #31
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    I'll change to solved because is like that, the code works, the speed issue is beyond the goal of my question, because with
    smaller files should work better.

    I've learned many things from this problem, I know a little bit of how to use ADO to get info from closed wrokbook. I would
    like to know more about this manipulations, I wasn't able to get good examples nor much info about this.

    Do you know a link or reference where to learn more of this particular subject?

    Many thanks romperstomper for all your great and kindly help. You know a lot.

    PS: If I'm not wrong, the guy the image is Socrates in Azteca stadium, World Cup 1986, right? you are a fan of him I guess .

    Best regards,

    César.

  32. #32
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Get matching values using ADO from closed CSV file

    One of the best online references for ADO with Excel I know of is here.

    You are correct about Socrates. Great player.

  33. #33
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Re: Get matching values using ADO from closed CSV file

    Great!!! Many thanks for all man!!!

    Best regards

+ 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