View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Chris Chris is offline
external usenet poster
 
Posts: 788
Default Unknown error in function, and how to return value?

Ok, I can tell it's close, because some dates are working.... But some
aren't, and I can't tell why. I tried to disable the "if error" part by
making it a comment and it was still showing "0" under some dates that should
not have... That tells me it obviously didn't error out, but for some reason
it isn't including the rows for those dates.

Here's the function exactly:

Function SalesTotal() As Integer
Dim varDate As Date
Dim c As Range
varDate = ActiveCell.Offset(-1).Value
LastRow = Sheet19.Cells(Rows.Count, "M").End(xlUp).Row
Set MyRange = Sheet19.Range("M" & ActiveCell.Row & ":M" & LastRow)
For Each c In MyRange
If c.Value = varDate Then
SalesTotal = SalesTotal + c.Offset(, 2).Value
End If
Next
If IsError(SalesTotal) Then SalesTotal = 0
End Function

If you notice, the sheet is now by number. Also, I found that the only date
this is actually working on is 5/15/09. They're all in there exactly the
same with the dates showing but that's the only one that is correct, and not
0.