Dave thanks for the reply!
This is what I have so far
Sub Example2()
Dim MyPath As String
Dim FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long
Dim Fnum As Long
Dim mybook As Workbook
Dim basebook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim rnum As Long
Dim sfolder As String
sfolder = ThisWorkbook.Path
'Fill in the path\folder where the files are
'MyPath = "C:\Data" or on a network :
MyPath = sfolder
MsgBox (MyPath)
'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xls")
MsgBox (FilesInPath)
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
On Error GoTo CleanUp
Application.ScreenUpdating = False
Set basebook = ThisWorkbook
'clear all cells on the first sheet
basebook.Worksheets(1).Cells.Clear
rnum = 1
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
MsgBox (FilesInPath)
'yymmdd.xls
If LCase(Right(FilesInPath, 10)) Like "*######.xls" Then
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
End If
FilesInPath = Dir()
Loop
'Loop through all files in the array(myFiles)
If Fnum > 0 Then
MyFiles = SortArray(MyFiles)
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
Set sourceRange = mybook.Worksheets(1).Range("g2:ae2")
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Range("A" & rnum)
' This will add the workbook name in column D if you want
basebook.Worksheets(1).Cells(rnum, "D").Value = mybook.Name
' sourceRange.Copy destrange
' Instead of this line you can use the code below to copy only
the Values
With sourceRange
Set destrange =
basebook.Worksheets(1).Cells(rnum, "A"). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
rnum = rnum + SourceRcount
mybook.Close savechanges:=False
Next Fnum
End If
CleanUp:
Application.ScreenUpdating = True
End Sub
Function SortArray(myArr As Variant) As Variant
Dim iCtr As Long
Dim jCtr As Long
Dim Temp As Variant
For iCtr = LBound(myArr) To UBound(myArr) - 1
For jCtr = iCtr + 1 To UBound(myArr)
If LCase(Right(myArr(iCtr), 10)) _
> LCase(Right(myArr(jCtr), 10)) Then
Temp = myArr(iCtr)
myArr(iCtr) = myArr(jCtr)
myArr(jCtr) = Temp
End If
Next jCtr
Next iCtr
End Function
It runs through the sort and then ends. What am I missing?
Thanks!
> Add this at the bottom of your module:
>
[quoted text clipped - 132 lines]
> > > >
> > > > Thanks!
Dave Peterson - 19 Jan 2006 21:48 GMT
Try using this Sub instead of the function:
Sub SortArray(myArr As Variant)
Dim iCtr As Long
Dim jCtr As Long
Dim Temp As Variant
For iCtr = LBound(myArr) To UBound(myArr) - 1
For jCtr = iCtr + 1 To UBound(myArr)
If LCase(Right(myArr(iCtr), 10)) _
> LCase(Right(myArr(jCtr), 10)) Then
Temp = myArr(iCtr)
myArr(iCtr) = myArr(jCtr)
myArr(jCtr) = Temp
End If
Next jCtr
Next iCtr
End Sub
And change the
myfiles = sortarray(myfiles)
to
Call SortArray(MyFiles)
> Dave thanks for the reply!
> This is what I have so far
[quoted text clipped - 243 lines]
> >
> > Dave Peterson

Signature
Dave Peterson
Dave Peterson - 19 Jan 2006 22:03 GMT
ps. That on error statement hides any errors. When you're debugging (or I'm
debugging), it's a good idea to comment that out to help find the problem.
> Try using this Sub instead of the function:
>
[quoted text clipped - 271 lines]
>
> Dave Peterson

Signature
Dave Peterson
Sandy - 20 Jan 2006 14:28 GMT
Thanks Dave
This is what I have so far. It appears as though the routine stops after
the sort array bit. When I run the code it highlightst he End Sub for Sort
Array but doesnt give an error message.
Thanks!
> ps. That on error statement hides any errors. When you're debugging (or I'm
> debugging), it's a good idea to comment that out to help find the problem.
[quoted text clipped - 274 lines]
> >
> > Dave Peterson
Sandy - 20 Jan 2006 16:06 GMT
I have it now thanks!
A followup question:
This code creates a grid with dates in A2:A31 and hourly data is in B2:Y31,
with hours 1-24 listed in B1:Y1. Then on sheet2 colA is date/time dd/mm/yyyy
hh:mm. Hww would I look up the coresponding values in the grid for for each
Date/Time on sheet2?
> ps. That on error statement hides any errors. When you're debugging (or I'm
> debugging), it's a good idea to comment that out to help find the problem.
[quoted text clipped - 274 lines]
> >
> > Dave Peterson
Dave Peterson - 20 Jan 2006 16:55 GMT
=index(match())???
You may want to read Debra Dalgleish's notes:
http://www.contextures.com/xlFunctions02.html (for =vlookup())
and
http://www.contextures.com/xlFunctions03.html (for =index(match()))
> I have it now thanks!
> A followup question:
[quoted text clipped - 285 lines]
> >
> > Dave Peterson

Signature
Dave Peterson
Sandy - 20 Jan 2006 17:20 GMT
Great! Thansk so much for your help!
> =index(match())???
>
[quoted text clipped - 276 lines]
> > > > > > > > date
> > > > > > > > > order but the code is opening newest last. What do I change to get them