Copying workbook to main workbook
I am trying to create a macro that will copy the data thats in a .csv file
and then copy it to a .xls (Excel Workbook) file, I wrote some code for it, but it's only copying the .xls files and when I change the fileformat to .csv it doesn't work at all, my code can be seen below: Sub CopyRange() Dim basebook As Workbook Dim mybook As Workbook Dim sourceRange As Range Dim destrange As Range Dim rnum As Long Dim i As Long Dim a As Long Application.ScreenUpdating = False With Application.FileSearch .NewSearch .LookIn = "S:\IndexServices\Alex\Test CDS\CMA Data\CMA Files" .SearchSubFolders = False .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then Set basebook = ThisWorkbook rnum = 1 For i = 1 To .FoundFiles.Count Set mybook = Workbooks.Open(.FoundFiles(i)) Set sourceRange = mybook.Worksheets(1).Range("a1:M600") a = sourceRange.Rows.Count Set destrange = basebook.Worksheets(2).Cells(rnum, 1) sourceRange.Copy destrange mybook.Close rnum = i * a + 1 Next i End If End With Application.ScreenUpdating = True End Sub I also want it so that when it is copying to the main workbook, it copy's after the last data that has been entered, meaning I don't want the data thats already on the sheet to be erased, but for it to just be added to the data thats already on the main workbook, does anyone know of a way to do this? |
All times are GMT +1. The time now is 10:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com