PC Review


Reply
Thread Tools Rate Thread

Copying workbook to main workbook

 
 
drinese18
Guest
Posts: n/a
 
      25th Feb 2008
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically closing slave workbook when main workbook is closed... Potsy Microsoft Excel Discussion 0 9th Mar 2010 11:48 AM
Automatically closing slave workbook when main workbook is closed... Potsy Microsoft Excel Discussion 0 9th Mar 2010 11:46 AM
Copying range from selected workbook to open workbook John Microsoft Excel Programming 2 11th Aug 2007 03:49 PM
copying worksheets to a new workbook without formulae referencing original workbook pjdeeb@gmail.com Microsoft Excel Programming 2 16th Oct 2006 07:31 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 Microsoft Excel Programming 1 1st Apr 2006 08:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:32 AM.