Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating sheets in Workbook from main sheet IMS Lori Excel Discussion (Misc queries) 0 January 28th 08 07:11 PM
copying worksheets to a new workbook without formulae referencing original workbook [email protected] Excel Programming 2 October 16th 06 07:31 PM
Copying data from workbook/sheets to another workbook/sheet yukon_phil Excel Programming 0 July 26th 06 07:33 PM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
Macro to link Sheets to main workbook raven_guy Excel Discussion (Misc queries) 0 June 24th 05 12:36 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"