Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Updating sheets in Workbook from main sheet | Excel Discussion (Misc queries) | |||
copying worksheets to a new workbook without formulae referencing original workbook | Excel Programming | |||
Copying data from workbook/sheets to another workbook/sheet | Excel Programming | |||
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook | Excel Programming | |||
Macro to link Sheets to main workbook | Excel Discussion (Misc queries) |