Fetching data from last row of multiple csv files in a folder to excel File1

manuadam

New Member
Joined
Oct 30, 2013
Messages
2
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:
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.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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.

No reply yet :(. Perhaps people no more come to this forum.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top