View Single Post
  #3   Report Post  
Dorn
 
Posts: n/a
Default How do I use a UDF?

Oops, the full function is the following (I made this mistake on the post,
not in my attempt to use it in excel so I'm still getting a syntax error)

Function GetTotals(Source As String, Resource As Range, MatchDate As Range)
Dim i As Long
Dim iLastrow As Long
Dim iStart As Long
Dim iEnd As Long
Dim tmp

iLastrow = Worksheets(Source).Cells(Worksheets(Source).Rows.C ount,
"A").End(xlUp).Row
On Error Resume Next
iStart = Application.Match(Resource.Value,
Worksheets(Source).Range("B:B"), 0)
If iStart 0 Then
iEnd = Application.Match("Agent:", Worksheets(Source).Range("A" &
iStart + 1 & ":A" & Rows.Count), 0) + iStart
If iEnd = 0 Then
iEnd = iLastrow
End If
On Error GoTo 0
For i = iStart To iEnd
If Worksheets(Source).Cells(i, "A").Value = MatchDate.Value Then
tmp = CDate(Worksheets(Source).Cells(i, "G").Value)
End If
Next i
End If
GetTotals = tmp

End Function