如何使用单元格中的十六进制颜色值突出显示单元格? [英] How to highlight a cell using the hex color value within the cell?

查看:486
本文介绍了如何使用单元格中的十六进制颜色值突出显示单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子表格的符号和匹配的十六进制颜色。我想用单元格中的十六进制颜色填充单元本身(或其旁边的单元格)。我已经阅读了一些有关条件格式化的内容,我认为这是这样做的。



我想如何实现我想要的结果? >

解决方案

无法通过条件格式化实现所有颜色。



假设:Row1包含数据标签,数据集没有间隙,HEX颜色是填充不是字体,您已经将HEX颜色值(数字,而不是公式)解析为列C:E( R,G,B),并且您不需要经常这样做,那么ColourCells宏可能适合:

  Sub ColourCells()
Dim HowMany As Integer
On Error Resume Next
Application.DisplayAlerts = False
HowMany = Application.InputBox _
(提示符:=输入最后一行号,标题:=要应用到多少行?,类型:= 1)
错误GoTo 0
Application.DisplayAlerts = True
如果HowMany = 0然后
退出Sub
Else
Dim i As Integer
对于i = 2 To HowMany
单元格(i,3).Interior.Color = RGB(单元格(i,3),单元格(i,4),单元格(i,5) ))
Next i
End If
End Sub

在出现提示时输入您想要的值n。



示例输出和公式等:





Excel的RGB()函数实际上创建一个BGR值(I不要以为任何人可能知道为什么说为什么),所以Excel以相反的顺序显示半字节。对于代码列3,4,5是逻辑的,但BGR而不是图像中的常规RGB,我认为可能看起来很奇怪。对于图像中的F,RGB三)的C3值( LEFT 手绘列​​)从将 RIGHT()应用于十六进制颜色导出。


I have a spreadsheet of symbols and matching hex colors. I want to fill the cell itself (or the one next to it) with the hex color within the cell. I've read a bit about "conditional formatting", and I think that's the way to do it.

How might I achieve the result I would like?

解决方案

Can't be achieved with Conditional Formatting for all colours.

Assuming: Row1 contains Data Labels, data set does not have gaps, the HEX colour is for the fill not the font, you have parsed the HEX colour values (numbers, not formulae) into Columns C:E (R,G,B) and that you do not require to do this often, then the ColourCells macro might suit:

Sub ColourCells()
Dim HowMany As Integer
On Error Resume Next
Application.DisplayAlerts = False
HowMany = Application.InputBox _
(Prompt:="Enter last row number.", Title:="To apply to how many rows?", Type:=1)
On Error GoTo 0
Application.DisplayAlerts = True
If HowMany = 0 Then
Exit Sub
Else
   Dim i As Integer
   For i = 2 To HowMany
      Cells(i, 3).Interior.Color = RGB(Cells(i, 3), Cells(i, 4), Cells(i, 5))
   Next i
End If
End Sub

and enter the value you want for n when prompted.

Sample output and formulae etc:

Excel's RGB() function actually creates a BGR value (I don't think anybody that might know why is saying why though) so Excel shows nibbles in reverse order. For the code Columns3,4,5 was logical but BGR rather than the conventional RGB in the image I thought might look odd. For F in the image the C3 value (the LEFT hand column of the 'RGB' three) is derived from applying RIGHT() to the Hex colour.

这篇关于如何使用单元格中的十六进制颜色值突出显示单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆