Looks like you're trying to update cells other than the cell where the function is running. that's not allowed using standard user defined functions as it breaks the execution model.
If you want to run a function in one cell that modifies values/layout of other cells the easiest way is to use the QueueAsMacro() function to run the code on the Macro thread after the UDF completes.