Consulting

Results 1 to 11 of 11

Thread: Filter large files without opening

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location

    Filter large files without opening

    Hi All.

    I have a file with approx. 400k rows of data.

    Is there a way (code) or general ideas, to filter this file without opening it, and given the filter criteria, only open what has been asked of the filter?

    Appreciate this is reasonably vague, but I have a blank canvas at the moment

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    What kind of file ?

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    Its a csv file within a zip

    Tx

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Why would you like to read it without opening it ?

  5. #5
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    ideally im wanting to filter by ''data type'' and open the file that only contains date type = ''54''

    Thanks

  6. #6
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    Why would you like to read it without opening it ?
    Hi

    Because the file generally holds around 400-600 rows of records and crashes my excel daily, and im unable to navigate through the workbook effectively.

    If I could strip out and open the workbook with only date type 54, it would open appx 20k rows of data, and be more manageable

    Tx

  7. #7
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    400-600 k rows

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    400k rows cant' be a problem.
    If it is, you should upgrade your hardware.

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Something like this can create a new filtered data file, which you could then import
    Sub test()
    'http://stackoverflow.com/questions/427488/want-vba-in-excel-to-read-very-large-csv-and-create-output-file-of-a-small-subse
    Set cN = CreateObject("ADODB.Connection")
    'Note HDR=Yes, that is, first row contains field names '
    'and FMT delimted, ie CSV '
    strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\TestDir\;" _
    & "Extended Properties=""text;HDR=Yes;FMT=Delimited"";"
    cN.Open strcon
    'You would not need delimiters ('') if last field is numeric: '
    strSQL = "SELECT * INTO New.csv FROM DataFile.csv " _
    & " WHERE Data_Type=54"
    'Creates new csv file
    cN.Execute strSQL
    End Sub
    Last edited by mdmackillop; 07-12-2016 at 05:17 AM. Reason: Header names omitted
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    VBAX Regular
    Joined
    Nov 2015
    Posts
    50
    Location
    oh, thank you so much, ill try this and revert back.

    Possibly the file contains more than 400k rows, that was a rough guess, however it crashes on every occasion, so unable to provide a definitive answer on that.

    thanks.

  11. #11
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Did you ever try ?

    Sub M_snb()
      c00=createobject("scripting.filesystemobject").opentextfile("G:\OF\example.csv").readall
      msgbox len(c00)
      msgbox ubound(split(c00,vbCrLf))
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •