问题
column A has:
table
pencil
table
table
paper
pencil
paper
so, all cells containing table
should have yellow color, pencil
should have blue, and paper
should have red color,
How to do this?
回答1:
Give your input range the name "Argument"
create another range "Template" where you list each element once and format it in the way you like (borders, styles, background colors etc. ...)
run the following code
Sub FormatFromList()
Dim ArgCell As Range, TemplateCell As Range
For Each ArgCell In Range("Argument").Cells
For Each TemplateCell In Range("Template").Cells
If ArgCell = TemplateCell Then
TemplateCell.Copy
ArgCell.PasteSpecial xlPasteFormats
Exit For
End If
Next TemplateCell
Next ArgCell
End Sub
If you want more automation, think of using a Worksheet_Change(...)
trigger to call FormatFromList()
来源:https://stackoverflow.com/questions/18629117/how-to-color-duplicate-cell-groups-with-different-color