Color a cell based on another cell... with a function

scottcolbury

New Member
Joined
Dec 6, 2005
Messages
45
Hi all,

I'm trying to write a worksheet function that will look at a cell on another worksheet, and then bring back both the value and color of the first cell.

For instance... I'm hoping to write something like this.
=GetColor(Range)

If I entered =GetColor(Sheet1!A1) in cells B2 on sheet2 then I would get both the value and color of Sheet1!A1 in Sheet2!B2.

I did some searching on the net and found ways to sum values based on colors, but nothing quite like this.

Here's the start of my code:

Code:
Function GetColor(InputCell As Range) As Double
Dim ColorRange As Integer

Application.Volatile True

    InputVal = InputCell.Value
    ColorRange = InputCell.Interior.ColorIndex

    GetColor = InputVal
    GetColor.Interior.ColorIndex = ColorRange
    
End Function

Obviously the following line doesn't work

GetColor.Interior.ColorIndex = ColorRange

Thanx in advance.
s_c
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Scott

I'm afraid you can't use a User Defined Function in a worksheet to alter the format of a cell.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,823
Members
449,470
Latest member
Subhash Chand

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