Share via

Why I see #VALUE! in excel while my function work well

Anonymous
2022-02-04T18:52:22+00:00

Hi everyone!

I write a function in Microsoft Visual Basic that gets a range of cells and another cell as argument and search in range and count how many cells have background color same as the second argument even if the color was set by a format condition.

the function works well when using "cell.DisplayFormat.Interior.Color" for compare colors but show "#VALUE!" instead output!

in another case when using "cell.Interior.Color" for compare colors it shows output but doesn't count correct because some cells set color with format condition and "cell.Interior.Color" just return default background color not the color that changes with format condition.

I have no idea what is happening, please help me.

here is the code of function with "cell.DisplayFormat.Interior.Color":

and the action of the code ( as you can see it count cells correct but don't show it ):

and here is the code of function with "cell.Interior.Color":

the action of this code ( as you can see it count cells wrong but show it well ):

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2022-02-04T22:13:10+00:00

Thanks for your answer.

Are you sure about it?

That's so weird.

I agree it is weird.

The function code will work if the function is called by a Sub routine or by calling it from "View Macros". It just won't work called from a worksheet cell.

There were comments in the Excel help file about this, but I can't find them now.

Also FWIW, a function called from a worksheet cell cannot alter/change another worksheet cell.

This was implemented many years ago as a security precaution.

'---
Nothing Left to Lose

https://1drv.ms/u/s!Au8Lyt79SOuhZw2MCH7_7MuLj04?e=sAwbHU

(free excel programs)

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2022-02-04T19:19:44+00:00

Re: Range.DisplayFormat property

The Range.DisplayFormat property is disabled in a user designed function (UDF) when called from a worksheet cell.

That is the way it was designed, you can't do anything about it.

'---

Nothing Left to Lose

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-02-05T07:39:52+00:00

    Thanks a lot for the help.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-02-04T20:20:08+00:00

    Thanks for your answer.

    Are you sure about it?

    That's so weird.

    Was this answer helpful?

    0 comments No comments