View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default custom function - with built-in function

Marton,

You function is being passed a range as its argument. HLOOKUP returns the
cell value, not the cell, so they have a basic dilemma.

You need to use a different function. MATCH will get you the column that A1
is in,

MATCH($A$1,$B$20:$B$51,0)

and INDEX can return the reference at the intersection of a column and a row

INDEX($B$20:$Q$51,J6, the_col)

Join them together and integrate with your function, and you get

=colorofcell(INDEX($B$20:$Q$51,J6,MATCH($A$1,$B$20 :$B$51,0)))

But also note that there is a basic problem with your function, in that it
will not update automatically if the cell colour is changed, you will need
to force a recalculation of the value with F9.


--

HTH

RP
(remove nothere from the email address if mailing direct)


"VilMarci" wrote in message
...
Hi,

I have a small excel function that returns the background color value of a
cell:

Function ColorOfCell(cellaneve As Range)

Dim CellColor As Integer

CellColor = cellaneve.Interior.ColorIndex
ColorOfCell = CellColor

End Function

That's ok. Works from excel like =ColorOfCell(A1)
But how can I make it work to use with built-in functions?

Like:
=ColorOfCell(HLOOKUP($A$1;Personal!$B$20:$Q$51;J6; FALSE))

Is there any general solution to do this?

Marton