Excel VBA,匹配字体颜色和单元格背景颜色

问题描述:

我有一个多张工作表。在表格“团队”中,我列出了每个团队的列表,每个单元格都有不同的背景和字体颜色。我想要另一张表(标题为“1”)查看“团队”中的列表,并且如果值匹配,则匹配背景和字体颜色。使用VBA和这个网站,我得到了背景颜色使用工作如下:Excel 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 

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 

是否有修改此代码(或使用其他代码)来检索字体颜色,以及一种方式?提前感谢您的任何见解。

只需添加另一行

rngColor.Font.Color = KeywordCell.Font.Color 
+0

这工作。谢谢! – Job 2014-09-01 05:15:00