Hi everyone. I am a complete and absolute beginner in the VBA area and Id like to ask the community for help.
The problem regards an issue that has been discussed in several topics, some of them really old like this one:
but in my case there is additional task to be solved.
I need to copy data from multiple csv. files (each of them consist only one worksheet) to one master worksheet. At first I'd like to copy information from columns "B" to "D" and then I'd like to add to column "A" source worksheet name. And to do that with all csv. files...
I used code already generated by famous user @mumps (You're a real hero mumps!), but I really struggle with adding the source worksheet name.
Here is the first part of the code that works perfectly...:
May I ask for help?
many thanks in advance...
m.
The problem regards an issue that has been discussed in several topics, some of them really old like this one:
VBA to copy data from multiple workbooks into master sheet
Hello Everyone! I have to copy data from 10+ workbooks and paste it into a master workbook. All the workbooks are located in a folder on my desktop: C:\Users\xbv\Desktop\group1 All the workbooks contain a sheet named 'appendix B', I have to open each workbook, go to sheet 'appendix B’, select...
www.mrexcel.com
but in my case there is additional task to be solved.
I need to copy data from multiple csv. files (each of them consist only one worksheet) to one master worksheet. At first I'd like to copy information from columns "B" to "D" and then I'd like to add to column "A" source worksheet name. And to do that with all csv. files...
I used code already generated by famous user @mumps (You're a real hero mumps!), but I really struggle with adding the source worksheet name.
Here is the first part of the code that works perfectly...:
VBA Code:
Sub CopyRange()
Application.ScreenUpdating = False
Dim wkbDest As Workbook
Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Const strPath As String = "c:\Users\michal\Documents\Macro\"
ChDir strPath
strExtension = Dir("*.csv*")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets(1).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets(1).Range("A1:E" & LastRow).Copy wkbDest.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
End Sub
May I ask for help?
many thanks in advance...
m.