如何使用不同的颜色来复制单元格组? [英] How to color duplicate cell groups with different color?

查看:131
本文介绍了如何使用不同的颜色来复制单元格组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A栏有:

 
铅笔



铅笔

所以,包含应该有黄色,铅笔应该有蓝色,而应该有红色,



如何做?

解决方案

输入范围名称参数



创建另一个范围模板,您可以在其中列出每个元素一次,并以您喜欢的方式(边框,样式,背景颜色等)进行格式化...)



运行以下代码

  Sub FormatFromList ()
Dim ArgCell As Range,TemplateCell As Range

对于每个ArgCell In Range(Argument)。Cells
对于范围内的每个TemplateCell(Template)。
如果ArgCell = TemplateCell然后
TemplateCell.Copy
ArgCell.PasteSpecial xlPasteFormats
退出
结束If
下一个TemplateCell
下一个ArgCell
End Sub

如果你想要更多的自动化,想想使用一个 Worksheet_Change(...)触发器来调用 FormatFromList()


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?

解决方案

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()

这篇关于如何使用不同的颜色来复制单元格组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆