Results 1 to 3 of 3

Reading in CSV files

Threaded View

FactCheckinCuz Reading in CSV files 11-13-2009, 12:25 PM
JBeaucaire Re: Reading in CSV files 11-13-2009, 12:47 PM
FactCheckinCuz Re: Reading in CSV files 11-16-2009, 06:13 AM
  1. #1
    Registered User
    Join Date
    11-13-2009
    Location
    Reading, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Reading in CSV files

    Hi there. I'm using the following code to read in any number of CSV files into a single worksheet and concatenating them together
    File_Path = "H:\pathname"
    
    strName = Dir(File_Path & "\" & "XXXXX*.CSV")  
    Do While strName <> vbNullString
    
        If active_workbook.Name <> strName And strName <> "" Then
            Workbooks.OpenText Filename:=File_Path & "\" & strName, startrow:=1, _
                DataType:=Excel.XlTextParsingType.xlDelimited, _
                TextQualifier:=Excel.XlTextQualifier.xlTextQualifierDoubleQuote, _
                Comma:=True, local:=True
            Set dataset_workbook = ActiveWorkbook
            Range(ActiveCell.SpecialCells(xlLastCell), Cells(1)).Copy
            active_sheet.Activate
            Cells(ActiveCell.SpecialCells(xlLastCell).Row + 1, 1).Select
            ActiveSheet.Paste
            dataset_workbook.Close
        End If
        strName = Dir
    Loop
    It works fine the first time I run it after opening the workbook (I've got 12 rows of data across 3 CSVs) 12 rows are pasted and 1 blank row at the beginning.

    The second time I run it it pastes into the worksheet starting from row 14, and then 27 the third time etc.

    Does anyone know a way I can make sure it always pastes starting from row 1?

    Thanks in advance.
    Last edited by FactCheckinCuz; 11-16-2009 at 06:19 AM.

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