G
Guest
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.Count,
"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!
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.Count,
"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!