C
Carlton L
I have a worksheet that looks up data in a table based on a desire
month number entered in a cell with a range name of "Month." Th
worksheet also looks up the YTD row totals for selected month from th
table. Without making the YTD formulas in the table a mess of neste
IF statements, I am attemting to write a custom function to include i
the YTD total only the months through the entered month number. I a
new to VBA and wrote the following custom function (which does no
work):
Function YTDTotal(TotRng As Range) As Integer
' "Month" is the range name of the cell that contains the numbe
for the month.
MthNum = Range("Month").Value
ColAdj = MthNum - 12
NewRng = TotRng.Resize(, ColAdj)
YTDTotal = WorksheetFunction.Sum(NewRng)
End Function
Why does this not work? I get a #Value! error when I use it on th
worksheet.
Any help would be greatly appreciated
month number entered in a cell with a range name of "Month." Th
worksheet also looks up the YTD row totals for selected month from th
table. Without making the YTD formulas in the table a mess of neste
IF statements, I am attemting to write a custom function to include i
the YTD total only the months through the entered month number. I a
new to VBA and wrote the following custom function (which does no
work):
Function YTDTotal(TotRng As Range) As Integer
' "Month" is the range name of the cell that contains the numbe
for the month.
MthNum = Range("Month").Value
ColAdj = MthNum - 12
NewRng = TotRng.Resize(, ColAdj)
YTDTotal = WorksheetFunction.Sum(NewRng)
End Function
Why does this not work? I get a #Value! error when I use it on th
worksheet.
Any help would be greatly appreciated