+ Reply to Thread
Results 1 to 4 of 4

Copy row of data from daily csv to Master file

  1. #1
    Registered User
    Join Date
    05-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Copy row of data from daily csv to Master file

    Hi All,

    I'm pretty new to VBA so any help is much appreciated.

    I have an ftp folder to which a new csv file is uploaded every day with one row of headings in row 1, and 1 row of data in row 2 (Columns A-O). Each filename contains a date stamp in the form of 2013-06-14_DailyData.

    I need to write a macro that will copy the row of data every day and add it beneath the last row of data in the Master file. Column A in both the daily csv and master file contain the date in the same format.

    Any ideas on how to do this?

    Thanks,

    Ryan

  2. #2
    Registered User
    Join Date
    07-24-2013
    Location
    kentucky
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Copy row of data from daily csv to Master file

    Top, also have this issue

  3. #3
    Registered User
    Join Date
    05-15-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Copy row of data from daily csv to Master file

    This has done the job for me!

    Sub getdata()


    Const ForReading = 1, ForWriting = 2, ForAppending = 8 'Declaring constants
    Dim FSO, MyFile, FileName, TextLine
    Dim nextdate As Date
    sheettopastein = "Master"

    currow = 1
    Do Until ActiveWorkbook.Sheets(sheettopastein).Cells(currow, 2).Value = "" 'Start at row 1, search down until Column B = "" / Blank
    currow = currow + 1
    Loop

    nextdate = ActiveWorkbook.Sheets(sheettopastein).Cells(currow, 1).Value

    sFileloc = "\\C:\folder\" ' Select the file location

    sFilename = Format(nextdate, "yyyy-mm-dd") + "_counts.csv" ' Select which file you want to open for output

    fullfile = sFileloc + sFilename ' The file = the location + the filename

    Set FSO = CreateObject("Scripting.FileSystemObject") 'Creating the reference at run-time to allow us to manipulate a file
    Set MyFile = FSO.OpenTextFile(fullfile, ForReading) ' Set the Myfile identifier for the open file and open it for reading only

    MyFile.SkipLine ' skip a given number of lines starting from the current position within the file.

    Do While MyFile.AtEndOfStream <> True
    TextLine = MyFile.ReadLine

    Loop



    currow = 1
    Do Until ActiveWorkbook.Sheets(sheettopastein).Cells(currow, 1).Value = nextdate
    currow = currow + 1
    Loop

    currcol = 1

    ActiveWorkbook.Sheets(sheettopastein).Cells(currow, currcol).Value = TextLine

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Cells(currow, currcol).TextToColumns _
    Destination:=ActiveWorkbook.Sheets(sheettopastein).Cells(currow, currcol), _
    DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, _
    Tab:=False, _
    Semicolon:=False, _
    Comma:=True, _
    Space:=False, _
    Other:=False, _
    FieldInfo:=Array(1, 1), _
    TrailingMinusNumbers:=True

    Dim celldate As Date

    celldate = Cells(currow, currcol).Value
    Cells(currow, currcol).Value = celldate


    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

    MyFile.Close



    End Sub

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

    Re: Copy row of data from daily csv to Master file

    Please, use code tags !!

    You could try to use VBA :

    Please Login or Register  to view this content.
    You only have to adapt the foldername "G:\OF\"
    Last edited by snb; 07-25-2013 at 04:46 AM.



+ 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