Format a Cell from within a defined function

kkjensen

Active Member
Joined
Jun 22, 2004
Messages
354
Hi there,

I've written my own little function to do some particular bits of math that I don't want to have to repeat over and over.

When I write the function into a cell (not using my defined function) I generally do a custom format like:

[Red][>2]">2";0.00

I don't want to have my defined function outputting the text ">2" since I want to be able to link to the cell from other functions. Is there a way to (in a defined function) change the format of a cell to "custom" and enter something? I know how to do this in a macro using Activecell.numberformat = "0.00" etc etc but this does not work in a defined function. :oops:
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Functions can only return values. They can't perform actions like formatting cells, as you have discovered.

So the answer is no.
 
Upvote 0
Thanks.

I was always a bit curious about the differences between functions and macros. I thought they were essentilaly the same thing but a macro only ran when you told it to and a function updated according to the changing value of the other cells or values it refers to.
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top