G
Grymjack
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
#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