PC Review


Reply
Thread Tools Rate Thread

Copy range from multiple .xls files - output to separate columns per .xls file

 
 
qwerty01
Guest
Posts: n/a
 
      13th Jun 2007
I have a series of Excel files, and I have the code working to copy a
range from each and output into one sheet. When it is done with the
copy/paste from the first file, it continues to the next file but it
continues to paste in the cell directly below the last file. I need
it to start pasting the data in a new column per file. Here is what I
have so far:

Sub CopyRangeValues()
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 = "filepath"
.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("a5:c52")
a = sourceRange.Rows.Count
With sourceRange
Set destrange = basebook.Worksheets(1).Cells(rnum,
1). _

Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
mybook.Close
rnum = i * a + 1
Next i
End If
End With
Application.ScreenUpdating = True
End Sub

Let me know if any more info is needed.
Any help would be greatly appreciated.

-qwerty01

 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jun 2007
See
http://www.rondebruin.nl/copy3.htm

Use
Merge a range from all workbooks in a folder (next to each other)



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"qwerty01" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>I have a series of Excel files, and I have the code working to copy a
> range from each and output into one sheet. When it is done with the
> copy/paste from the first file, it continues to the next file but it
> continues to paste in the cell directly below the last file. I need
> it to start pasting the data in a new column per file. Here is what I
> have so far:
>
> Sub CopyRangeValues()
> 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 = "filepath"
> .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("a5:c52")
> a = sourceRange.Rows.Count
> With sourceRange
> Set destrange = basebook.Worksheets(1).Cells(rnum,
> 1). _
>
> Resize(.Rows.Count, .Columns.Count)
> End With
> destrange.Value = sourceRange.Value
> mybook.Close
> rnum = i * a + 1
> Next i
> End If
> End With
> Application.ScreenUpdating = True
> End Sub
>
> Let me know if any more info is needed.
> Any help would be greatly appreciated.
>
> -qwerty01
>

 
Reply With Quote
 
qwerty01
Guest
Posts: n/a
 
      13th Jun 2007
That worked perfectly. Thank you Ron. Your site has been bookmarked,
and I will check there before posting any other questions from now on.

-qwerty01

 
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
select range in column, calculate on range plus 3 columns, output inrange plus 7 columns ppeer Microsoft Excel Programming 8 11th Feb 2010 09:14 PM
vb.net write output to separate excel files douglas Microsoft VB .NET 0 30th Mar 2009 04:07 AM
get range from excel sheet of separate columns using c# =?Utf-8?B?a29ieWNvb2w=?= Microsoft Excel Programming 0 22nd Jun 2006 03:00 PM
Copy columns values into separate columns =?Utf-8?B?TWlrZV9jYW4=?= Microsoft Excel Misc 7 27th May 2006 12:32 AM
File with multiple versions larger than separate files =?Utf-8?B?U2hvIE51ZiE=?= Microsoft Word Document Management 1 8th Feb 2005 03:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:20 AM.