Dear Sir, I need some help to get data from the last rows of multiple csv files in a data folder to my excel File1. I have named this File1.xlsm.
In the first column of this file, I have fetched the file-names of csv files of that data folder. For this I have used the following module/micro:
Now after getting proper names of different stocks (from file names of csv files in data folder) in Column A of my File1, my next step is to fetch the data from those csv files. But I want just the last row of that data as data there is changing in realtime - hence, even the number of last row is dynamically changing every minute.
I have noted that in the archive of MRexcel.com there is a help about this: One member Mr Derek has suggested two solutions for such scenario.
However, for my requirement I need to get data from multiple sources, that is - multiple csv files, which I can't name one by one, rather I want source as a directory or folder instead of just a particular file.
Please help me how to do it. I hope I could make my query clear. Thanks in advance.
In the first column of this file, I have fetched the file-names of csv files of that data folder. For this I have used the following module/micro:
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "C:\test" '<<< Startup folder to begin searching from
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = Left(xFname$, Len(xFname$) - 14)
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub
Now after getting proper names of different stocks (from file names of csv files in data folder) in Column A of my File1, my next step is to fetch the data from those csv files. But I want just the last row of that data as data there is changing in realtime - hence, even the number of last row is dynamically changing every minute.
I have noted that in the archive of MRexcel.com there is a help about this: One member Mr Derek has suggested two solutions for such scenario.
Dim NextRow As Long
Application.ScreenUpdating = False
NextRow = Range("C65536").End(xlUp).Row '+ 1
Cells(NextRow, 3).Select
Range(ActiveCell, ActiveCell.Offset(0, 4)).Copy
Windows("File2.xls").Activate
NextRow = Range("C65536").End(xlUp).Row + 1
Cells(NextRow, 3).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Windows("File1.xls").Activate
Application.ScreenUpdating = True
End Sub
[h=2]Or ....[/h]Posted by Guthrum on February 09, 2002 11:38 AM
Dim source As Range, dest As Range
Set source = Workbooks("File1.xls").Worksheets("Sheet1").Range("C65536").End(xlUp).Resize(, 5)
Set dest = Workbooks("File2.xls").Worksheets("Sheet1").Range("C65536").End(xlUp).Resize(, 5).Offset(1, 0)
source.Copy dest
However, for my requirement I need to get data from multiple sources, that is - multiple csv files, which I can't name one by one, rather I want source as a directory or folder instead of just a particular file.
Please help me how to do it. I hope I could make my query clear. Thanks in advance.