Excel User Defined Function: change the cell's color

excel, vba

Solution

This cannot be done. User defined functions cannot change the state of the workbook/worksheet etc.

Use Conditional Formatting to achieve what you are trying.

EDIT: This is more of a suggestion, not a real answer.

Problem

I have a user defined function in Excel. It is called as a formula function from spreadsheet cells and works fine. I'd like the function to be able to change the cell's color depending on the value that it returns. Essentially, changing the cell's color is a side effect of the function. I tried ``` Application.ThisCell.Interior.ColorIndex = 2 ``` But it fails.

Original source

Related problems