LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 788
Default Unknown error in function, and how to return value?

Hi all,

I've been working on this sheet for a bit, and I'm stuck at this point,
where I have a worksheet created like a calendar. My goal is to have a
function that pulls the date from the cell above it, searches another
worksheet in column "M" for matches to that date, add all of those rows'
column "O" together, and return the sum to range where I called the function.
Below is what I came up with, but I'm getting an error and don't know why,
and I also don't know how to return the variable.

Function SalesTotal()
Dim varDate As Date
Dim LSearchRow, varSaleTotal As Integer
' Search date needs to be same column, one row up
varDate = Range((Target.Row - 1) & Target.Column).Value


On Error GoTo Err_Execute
' Setup search from sheet 17

Sheet17.Select
LSearchRow = 2
While Len(Range("A" & CInt(LSearchRow)).Value) 0
If Range("M" & CInt(LSearchRow)).Value = varDate Then


'Add found range to var

varSaleTotal = varSaleTotal + (Range("O" &
CInt(LSearchRow)).Value)

'Go back to Sheet17 to continue searching

Sheet17.Select
End If
LSearchRow = LSearchRow + 1
Wend
Exit Function

Err_Execute:
MsgBox "An error occurred."


End Function

Thanks in advance for any help.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mode function - return default value rather than #N/A error if no Struggling in Sheffield[_2_] New Users to Excel 4 March 27th 09 06:27 PM
Unknown Formula Error Shaunna H. Excel Worksheet Functions 2 February 4th 09 07:14 AM
unknown #value error nomadwolf Excel Discussion (Misc queries) 0 August 17th 07 02:19 AM
Unknown Error aftamath Excel Discussion (Misc queries) 4 October 6th 05 07:08 PM
Error Return Value from and INDEX(A:2,MATCH()) function BJ Excel Worksheet Functions 4 January 26th 05 02:59 PM


All times are GMT +1. The time now is 08:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"