How to color duplicate cell groups with different color?

六眼飞鱼酱① 提交于 2019-12-08 08:32:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!