Maybe I'm trying to do too much here, but I've worked for hours on this with no luck. I hope you can help.
I am creating a function whose only parameter is a named range on a another sheet in the same workbook. My problem is that I can't figure out how to pass that name into the function and use it.
My goal is call the function to sum the column specified by the named range on the other worksheet, called Client Payments.
Here's my code that works:
Function PayPerMonth()
PayPerMonth = Application.WorksheetFunction.Sum(Worksheets("Client Payments").Range("C:C"))
End Function
I get a total that is correct, but of course I specified the column in the function. Not too useful.
Here's what I tried that doesn't work:
Function PayPerMonth(ColumnToAdd)
PayPerMonth = Application.WorksheetFunction.Sum(Worksheets("Client Payments").Range("ColumnToAdd"))
End Function
It doesn't work when I remove the quotes around ColumnToAdd, and many other variations I have tried.
What I want to do is to enter =PayPerMonth(MBPADV) or =PayPerMonth(SBTSADV) etc. to call the function and aim at the right column, where MBPADV and SBTSADV are named columns.
I'm not hung up on using the column names. It just makes it more readable (to me, anyway!).
Can this be done?