Excel VBA,匹配字体颜色和单元格背景颜色 [英] Excel VBA, Match Font Color and Cell Background Color

查看:828
本文介绍了Excel VBA,匹配字体颜色和单元格背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张带多页的工作簿。在表格团队我有一个列表的每个团队,每个单元格有独特的背景和字体颜色。我想要另一张表(标题为1)查看团队列表,如果值匹配,则匹配背景和字体颜色。使用VBA和这个网站,我得到背景颜色工作使用以下:

  Sub MatchHighlight()

Dim wsHighlight As Worksheet
Dim wsData As Worksheet
Dim rngColor As Range
Dim rngFound As Range
Dim KeywordCell As Range
Dim strFirst As String

设置wsHighlight = Sheets(Teams)
设置wsData = Sheets(1)

使用wsData.Columns(C)
对于每个KeywordCell in wsHighlight.Range(C2,wsHighlight.Cells(Rows.Count,C)。End(xlUp))。单元格
设置rngFound = .Find(KeywordCell.Text,.Cells(.Cells)计数),xlValues,xlWhole)
如果没有rngFound是没有
strFirst = rngFound.Address
设置rngColor = rngFound
Do
设置rngColor = Union(rngColor, rngFound)
设置rngFound = .Find(KeywordCell.Text,rngFound,xlValues,xlWhole)
循环while rngFound.Address<> strFirst
rngColor.Interior.Color = KeywordCell.Interior.Color
End If
Next KeywordCell
End with

End Sub

有没有办法修改此代码(或使用其他代码)来检索字体颜色?感谢您提前了解任何见解。

解决方案

只需添加另一行

  rngColor.Font.Color = KeywordCell.Font.Color 


I have a workbook with multiple sheets. On sheet "Teams" I have a list of every team, and each cell has a distinct background and font color. I want another sheet (entitled "1") to look at the list on "Teams", and if a value matches, to then match the background and font color. Using VBA and this site, I got the background color to work using the following:

Sub MatchHighlight()

Dim wsHighlight As Worksheet
Dim wsData As Worksheet
Dim rngColor As Range
Dim rngFound As Range
Dim KeywordCell As Range
Dim strFirst As String

Set wsHighlight = Sheets("Teams")
Set wsData = Sheets("1")

With wsData.Columns("C")
    For Each KeywordCell In wsHighlight.Range("C2", wsHighlight.Cells(Rows.Count, "C").End(xlUp)).Cells
        Set rngFound = .Find(KeywordCell.Text, .Cells(.Cells.Count), xlValues, xlWhole)
        If Not rngFound Is Nothing Then
            strFirst = rngFound.Address
            Set rngColor = rngFound
            Do
                Set rngColor = Union(rngColor, rngFound)
                Set rngFound = .Find(KeywordCell.Text, rngFound, xlValues, xlWhole)
            Loop While rngFound.Address <> strFirst
            rngColor.Interior.Color = KeywordCell.Interior.Color
        End If
    Next KeywordCell
End With

End Sub

Is there a way to modify this code (or use another code) to retrieve font color as well? Thank you in advance for any insights.

解决方案

Simply add another line

rngColor.Font.Color = KeywordCell.Font.Color

这篇关于Excel VBA,匹配字体颜色和单元格背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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