Funtions have limitations compared to subroutines. The following
quote comes from
http://www.j-walk.com/ss/excel/faqs/xl97faq3.htm
"Can a custom worksheet function written in VBA perform the same
types of actions as a subroutine?
No. Functions called from a worksheet formula have some limitations.
In general, they must be strictly "passive" -- they can't change the
active cell, apply formatting, open workbooks, change the active
sheet, and so on.
Functions can only perform calculations and return a value. An
exception to this rule is the VBA MsgBox function. A custom function
can display a MsgBox whenever it is recalculated. This is very handy
for debugging a custom function."
Possible options are to use a message box if you want to keep it as
a function, or use a subroutine and trigger your subroutine on the
Worksheet_Change event, button press, or another event.