跳到主要内容

如何确定和识别Excel中单元格的背景色索引?

在某些情况下,当您收到包含多个彩色单元的工作表时,如下面的屏幕截图所示,您可能需要识别这些颜色单元的背景颜色索引。 没有内置功能可以确定单元格的颜色索引,但是,在本文中,我介绍了一些VBA代码来快速解决Excel中的这项工作。
doc确定颜色索引1

用VBA识别电池的颜色


用VBA识别电池的颜色

请按照以下步骤通过VBA确定单元格的颜色。

1。 按 Alt + F11键 启用 Microsoft Visual Basic应用程序 窗口。
doc确定颜色索引2

2。 点击 插页 > 模块 打开一个新的 模块 并将以下VBA代码粘贴到空白脚本。 看截图:

VBA:获取单元格的传统十六进制代码

Function getRGB1(FCell As Range) As String
'UpdatebyExtendoffice20170714
    Dim xColor As String
    xColor = CStr(FCell.Interior.Color)
    xColor = Right("000000" & Hex(xColor), 6)
    getRGB1 = Right(xColor, 2) & Mid(xColor, 3, 2) & Left(xColor, 2)
End Function
doc确定颜色索引3
doc确定颜色索引4

3.保存代码并关闭VBA窗口。 选择一个彩色单元格旁边的空白单元格,键入此公式, = getRGB1(A16),然后将自动填充手柄拖到要使用的单元格上。 看截图:

doc确定颜色索引5
doc确定颜色索引6

提示: 还有一些其他代码可以识别单元格的颜色索引。

1. VBA:每个代码的十进制值

Function getRGB2(FCell As Range) As String
   'UpdatebyExtendoffice20170714  
    Dim xColor As Long
    Dim R As Long, G As Long, B As Long
    xColor = FCell.Interior.Color
    R = xColor Mod 256
    G = (xColor \ 256) Mod 256
    B = (xColor \ 65536) Mod 256
    getRGB2 = "R=" & R & ", G=" & G & ", B=" & B
End Function

结果:
doc确定颜色索引7

2. VBA:十进制值

Function getRGB3(FCell As Range, Optional Opt As Integer = 0) As Long
 'UpdatebyExtendoffice20170714
    Dim xColor As Long
    Dim R As Long, G As Long, B As Long
    xColor = FCell.Interior.Color
    R = xColor Mod 256
    G = (xColor \ 256) Mod 256
    B = (xColor \ 65536) Mod 256
    Select Case Opt
        Case 1
            getRGB3 = R
        Case 2
            getRGB3 = G
        Case 3
            getRGB3 = B
        Case Else
            getRGB3 = xColor
    End Select
End Function

结果:
doc确定颜色索引8


在Excel范围内快速选择重复或唯一值

在Excel工作表中,如果您的范围包含一些重复的行,则可能需要选择它们或将其突出显示,但是如何快速解决此工作? Kutools for Excel,你可以使用 选择复制并 独特的细胞 实用程序可快速选择范围内的重复项或唯一值,或为重复项和唯一值填充背景和字体颜色。  点击免费试用30天!
doc在第6列中突出显示重复项
 
Kutools for Excel:拥有300多个便捷的Excel加载项,可以在30天内免费试用。

相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Goededag,

Graag wil ik vragen waarom deze aanpak niet werkt met cellen die voorwaardelijk opgemaakt zijn!?
Alle codes die ik kan vinden geven allemaal de kleur "geen opvulling" als resultaat terug op de functies.

Hoop van jullie te horen!
This comment was minimized by the moderator on the site
I'm sorry, the site translates by itself...

I'm wondering why this doesnt work with colored cells using conditional formatting.
All programs on this page give a "blank" result, so no color at all even though the cell is colored.
If I color the cell myself instead of conditional formatting I get the right result back but i need the conditional formatting too!

Hope to hear from you!
This comment was minimized by the moderator on the site
Excelente Post, me ajudou. Parabéns
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations