Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 5221|回复: 7

怎样优化条件格式录制的宏代码?

[复制链接]
发表于 2010-7-12 14:28 | 显示全部楼层 |阅读模式
各位老师:
下面是在用条件格式录制的宏代码,可是只能在一个表中用,不能在sheet1——5表中共用,希望各位老师帮忙更改和优化一下,在此谢谢了!
Sub Macro2()
' 宏由 微软用户 录制,时间: 2010-7-10
    Range("CH:CN,DZ:ET").Select
    Range("DZ1").Activate
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""rr"""                                                       '当等于热时为粉红字;当等于温时,为砖红色字
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .ColorIndex = 7
    End With
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""ww"""
    With Selection.FormatConditions(2).Font
        .Bold = False
        .Italic = True
        .ColorIndex = 3
    End With
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""ll"""
    With Selection.FormatConditions(3).Font
        .Bold = True
        .Italic = True
        .ColorIndex = 4
    End With
    Range("CV:DB,EX:FR").Select
    Range("EX1").Activate
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""cc"""
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .ColorIndex = 7
    End With
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""nn"""
    With Selection.FormatConditions(2).Font
        .Bold = False
        .Italic = True
        .ColorIndex = 3
    End With
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""kk"""
    With Selection.FormatConditions(3).Font
        .Bold = True
        .Italic = True
        .ColorIndex = 4
    End With
    Range("DJ:DP,FV:GP").Select
    Range("FV1").Activate
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""ff"""
    Selection.FormatConditions(1).Font.ColorIndex = 7
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""gg"""
    With Selection.FormatConditions(2).Font
        .Bold = False
        .Italic = True
        .ColorIndex = 3
    End With
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""zz"""
    With Selection.FormatConditions(3).Font
        .Bold = True
        .Italic = True
        .ColorIndex = 4
    End With
    Columns("CH:GP").Select
    With Selection.Font
        .Name = "宋体"
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    With Selection.Font
        .Name = "宋体"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    Selection.ColumnWidth = 2.5
Selection.ColumnWidth = 3.13
End Sub
发表于 2010-7-12 14:40 | 显示全部楼层
回复

使用道具 举报

发表于 2010-7-12 14:44 | 显示全部楼层
回复

使用道具 举报

发表于 2010-7-12 14:44 | 显示全部楼层

学习下

回复

使用道具 举报

发表于 2010-7-12 15:47 | 显示全部楼层

上传附件,并把你的要求讲清楚
回复

使用道具 举报

 楼主| 发表于 2010-7-12 17:22 | 显示全部楼层

录制的条件格式代码能否作如下修改?

QUOTE:
以下是引用那么的帅在2010-7-12 15:47:00的发言:
上传附件,并把你的要求讲清楚

老师:
下面是在用条件格式录制修改后的一段代码,可是运行时出现类型不匹配的错误?,希望老师帮忙更改和优化一下,并且能在sheet1——5表中共用,在此谢谢了!
Sub Macro()'

' 宏由 微软用户 录制,时间: 2010-7-10
Range("CH:CN,DZ:ET").Select
    Range("DZ1").Activate
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
       Formula1:="=""★" Or "=""■" Or "=""▲" Or "=""◎"                                                       '当等于★、■、▲、◎时为粉红字   
With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .ColorIndex = 7
    End With
  Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="=""☆" Or "=""□" Or "=""△" Or "=""㊣"  
With Selection.FormatConditions(2).Font
        .Bold = False
        .Italic = True
        .ColorIndex = 3
    End With
Columns("CH:GP").Select
    With Selection.Font
        .Name = "宋体"
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    With Selection.Font
        .Name = "宋体"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    Selection.ColumnWidth = 2.5
Selection.ColumnWidth = 3.13   
End Sub

 

VlHMXn7N.zip (90.2 KB, 下载次数: 5)
回复

使用道具 举报

发表于 2010-7-12 21:52 | 显示全部楼层

这宏真复杂

回复

使用道具 举报

发表于 2019-6-12 19:18 | 显示全部楼层
我想知道  这宏是怎么录制的?  我在表格里设置条件格式,  录制后没内容.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 11:48 , Processed in 2.852725 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表