Excel VBA, Match Font Color and Cell Background Co

2019-09-19 16:00发布

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.

标签: excel vba
1条回答
劫难
2楼-- · 2019-09-19 16:42

Simply add another line

rngColor.Font.Color = KeywordCell.Font.Color
查看更多
登录 后发表回答