Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default summing a range in a UDF

Grrrr....is there some better way of doing this?? The UDF throws a
#VALUE error every time it hits any of the lines with a SUM in it.

ex: "n_Total = Application.WorksheetFunction.Sum(s_Start_Book + s_Sheet
+ s_Start_Cell + ":" + s_End_Cell)"

What am I screwing up with this line? The only other way I see of doing
it is step through range with a loop?....but this should work? Thank
you for anyone who takes the time to step through this monstrosity....

#### normal values passed in would be
s_Product_Code "6697"
n_Usage_Days = 9
n_Start_Date = "06/19/2006"
####

Function SUM_ORDER_RANGE(s_Product_Code As String, _
n_Usage_Days As Integer, _
n_Start_Date As Date) As Integer

Rem *Application.Volatile

Rem *tracks total in the order cells
Dim n_Total As Integer

Rem *setting book and sheet variable
Dim s_Start_Book As String
Dim s_End_Book As String
Dim s_Sheet As String
Dim s_Start_Cell As String
Dim s_End_Cell As String
Dim s_Crossover_Start_Cell As String
Dim s_Crossover_End_Cell As String

Rem *setting beginning variable amounts
n_Total = 0
s_Start_Book = "[Orders_" + Format(n_Start_Date, "mmmm") + "_" +
Format(n_Start_Date, "yyyy") + ".xls]"
s_End_Book = "[Orders_" + Format((n_Start_Date + n_Usage_Days),
"mmmm") + "_" + Format((n_Start_Date + n_Usage_Days), "yyyy") + ".xls]"
s_Sheet = "Orders!"
s_Start_Cell = "O_" + s_Product_Code + "_" + Format(n_Start_Date, "dd")
s_End_Cell = "O_" + s_Product_Code + "_" + Format((n_Start_Date +
n_Usage_Days), "dd")
s_Crossover_Start_Cell = "O_" + s_Product_Code + "_01"
s_Crossover_End_Cell = "O_" + s_Product_Code + "_31"

Rem *testing for month/year changeover
If (s_Start_Book < s_End_Book) Then
Rem *month/year crossover
n_Total = Application.WorksheetFunction.Sum(s_Start_Book +
s_Sheet + s_Start_Cell + ":" + s_Crossover_End_Cell)
n_Total = n_Total +
Application.WorksheetFunction.Sum(s_End_Book + s_Sheet +
s_Crossover_Start_Cell + ":" + s_End_Cell)
Else
Rem *search range within single month
n_Total = Application.WorksheetFunction.Sum(s_Start_Book +
s_Sheet + s_Start_Cell + ":" + s_End_Cell)
End If

Rem * returning the total to the cell
SUM_ORDER_RANGE = n_Total
End Function
Reply
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
Summing a range of cells based on criteria in another range Jack Excel Worksheet Functions 2 November 5th 09 01:46 AM
Summing a Range With N/A's SamuelT Excel Discussion (Misc queries) 3 June 19th 06 04:51 PM
Summing a range that changes Jeff Excel Discussion (Misc queries) 6 January 9th 06 10:57 PM
Summing a range. Please Help! [email protected] Excel Programming 5 March 4th 05 10:11 PM
summing range Tim Johnson[_2_] Excel Programming 4 July 27th 04 09:12 PM


All times are GMT +1. The time now is 06:11 PM.

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

About Us

"It's about Microsoft Excel"