2014-08-30 564 views
-1

我有一個多張工作表。在表格「團隊」中,我列出了每個團隊的列表,每個單元格都有不同的背景和字體顏色。我想要另一張表(標題爲「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 

是否有修改此代碼(或使用其他代碼)來檢索字體顏色,以及一種方式?提前感謝您的任何見解。

回答

0

只需添加另一行

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

這工作。謝謝! – Job 2014-09-01 05:15:00

相關問題