View Single Post
  #4   Report Post  
Chip Pearson
 
Posts: n/a
Default How do I use a UDF?

You are missing an End If and a Next statement. Properly indent
your code and you'll see exactly where to put these lines of
code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Dorn" wrote in message
...
A udf was made for me and I'm positive that it works, however
when I try to
use it I get a "syntax error" and it highlights the first line
of the code.
I've tried copying and pasting multiple UDF's and get the same
result... what
am I doing wrong? Just to clarify I've included all of the
information I can
think of below:

Here is the udf:

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

Here is the function I'm entering into B2:
=GetTotals("Sheet1",$A2,B$1)

The error pops up when I enter the above function into the
spreadsheet.
Any help would be much appreciated!