View Single Post
  #5   Report Post  
jonesaa05
 
Posts: n/a
Default


Hi, Dave

I post the code which I use to copy values from at least 2 workbook in
the same folder. Only the values from 1 workbook are correctly copied.
The others give 0 values. Please help me to have a look whether the is
the code problems. One more thing, which line of code to be changed if
I don't want to copy to the first sheet. Sorry, I am still novice to
VBA coding things.

Thanks in advanced,
amy

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 = "D:\Data\"
.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:k10")
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 'What does this means??

Next i
End If
End With
Application.ScreenUpdating = True
End Sub


--
jonesaa05
------------------------------------------------------------------------
jonesaa05's Profile: http://www.excelforum.com/member.php...o&userid=28021
View this thread: http://www.excelforum.com/showthread...hreadid=475287