Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy range from multiple .xls files - output to separate columns per .xls file

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Copy range from multiple .xls files - output to separate columns per .xls file

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" wrote in message oups.com...
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy range from multiple .xls files - output to separate columns per .xls file

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
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
Unwanted breaking up of print output into multiple files Atreides Setting up and Configuration of Excel 4 August 15th 08 08:18 PM
Hide columns and rows then separate the spreadsheet into different files tahrah Excel Programming 1 January 10th 07 06:24 PM
Comparing two columns in two separate files K Landsworth New Users to Excel 1 June 15th 06 11:43 AM
Import 2 text files into 2 separate columns? tcurrier Excel Discussion (Misc queries) 3 February 11th 06 07:13 PM
How do I pull data from multiple files and copy into one file JT Excel Programming 2 May 3rd 05 07:42 PM


All times are GMT +1. The time now is 09:06 AM.

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

About Us

"It's about Microsoft Excel"