通过自定义公式格式化单元格

我想在工作表中实现自定义function,以便可以在单元格中input数字,并将单元格颜色更改为该数字的RGB值。 是否可以用自定义公式来做到这一点? 说,在单元格中的公式将看起来像这样=SHOWCOLOR(123456)和VB函数将如下所示:

 Function ShowColor(cv As Integer) ActiveCell.Select With Selection.Interior .color = cv End With End Function 

我试过这种方法,但得到“错误的types数据值”的错误。

一个函数只能返回一个值,但事件macros:

 Private Sub Worksheet_Change(ByVal Target As Range) Target.Interior.Color = Target.Value End Sub 

会得到你想要的function。