largeselection
Active Member
- Joined
- Aug 4, 2008
- Messages
- 358
Hi,
I'm a novice so please bear with me...
I'm trying to modify some code from RDB to copy a range (one row, ~40 columns) from many workbooks (500+) into one.
I just found out that the application.FileSearch which he uses has since been discontinued from Excel 2007+. I looked up a number of the replacements that people have proposed, but a lot of them are using dir and objFSO and propose methods of counting files in a folder, but not counting them and then referencing them.
Here is the code I would like to use, but can't because of that discontinued FileSearch. If you have any insight or ideas as to how I can adjust it to be able to both count the # of files and then be able to loop through the routine to copy the same range from every file I'd appreciate it.
I'm a novice so please bear with me...
I'm trying to modify some code from RDB to copy a range (one row, ~40 columns) from many workbooks (500+) into one.
I just found out that the application.FileSearch which he uses has since been discontinued from Excel 2007+. I looked up a number of the replacements that people have proposed, but a lot of them are using dir and objFSO and propose methods of counting files in a folder, but not counting them and then referencing them.
Here is the code I would like to use, but can't because of that discontinued FileSearch. If you have any insight or ideas as to how I can adjust it to be able to both count the # of files and then be able to loop through the routine to copy the same range from every file I'd appreciate it.
Code:
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
Dim MemID As Integer
Dim sourceRange2 As Range
Dim destrange2 As Range
MemID = Worksheets("START").Range("C12").Value + 1
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = \\Directors\Data\Div 25
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
Set basebook = ThisWorkbook
rnum = 8
For i = 1 To .FoundFiles.Count
Set mybook = Workbooks.Open(.FoundFiles(i))
Set sourceRange = mybook.Worksheets(1).Range("E" & MemID & ":AQ" & MemID & "")
a = sourceRange.Rows.Count
With sourceRange
Set destrange = basebook.Worksheets("DATA").Cells(rnum, 2). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
Set sourceRange2 = mybook.Worksheets(1).Range("B3")
With sourceRange2
Set destrange2 = basebook.Worksheets("DATA").Cells(rnum, 1). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange2.Value = sourceRange2.Value
mybook.Close
rnum = i * a + 1
Next i
End If
End With
Application.ScreenUpdating = True
End Sub