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. I would like to create a function or subroutine that automatically changes the formatting of a cell based on the data I enter. For example, if I enter a value greater than 0, the cell’s background color should be red. Is this possible? It’s certainly possible, and you don’t need any programming. Use Excel’s Conditional Formatting feature, accessed with the Format – Conditional Formatting command. The Conditional Formatting features is useful, but I’d like to perform other types of operations when data is entered into a cell. In that case,
Related Questions
- I have a custom function that will be used in a worksheet formula. If the user enters arguments that are not appropriate, how can I make the function return a true error value (#VALUE)?
- Can a custom worksheet function written in VBA perform the same types of actions as a subroutine?
- Is it possible to pass arguments to a VBA subroutine executed by a custom menu?