Hi All,
I need to loop through sheets in a workbook to copy out a range of data. I have posted some code below. My issue is that it is not moving onto the next sheet to copy the data.
Am I missing something? Am I missing a reference?
vaneagle
I need to loop through sheets in a workbook to copy out a range of data. I have posted some code below. My issue is that it is not moving onto the next sheet to copy the data.
Code:
Sub getdata()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim ws As Worksheet
MyPath = "U:\My Documents\Testing\data\"
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
For Each ws In ActiveWorkbook.Worksheets
nrow = LastRow("A")
Range("a1:G" & nrow).Select
Selection.Copy
Next ws
wb.Close
TheFile = Dir
Loop
End Sub
Am I missing something? Am I missing a reference?
vaneagle