Excel精英培训网

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

[已解决]如何用VBA来设置条件格式

[复制链接]
发表于 2013-5-23 16:05 | 显示全部楼层 |阅读模式
在单元格(A3:A100)里,当单元格不为空时。不为空的单元格用红色填充。如果该单元格再次为空时,则该单元格恢复为无填充。
最佳答案
2013-5-23 16:23
  1. Sub 宏1()
  2.     With Range("a3:a100")
  3.         Range("a3").Activate
  4.         .FormatConditions.Delete
  5.         .FormatConditions.Add Type:=xlExpression, Formula1:="=LEN(A3)>0"
  6.         .FormatConditions(1).SetFirstPriority
  7.         With .FormatConditions(1).Interior
  8.             .PatternColorIndex = xlAutomatic
  9.             .Color = 255
  10.             .TintAndShade = 0
  11.         End With
  12.     End With
  13. End Sub
复制代码
发表于 2013-5-23 16:16 | 显示全部楼层
回复

使用道具 举报

发表于 2013-5-23 16:23 | 显示全部楼层    本楼为最佳答案   
  1. Sub 宏1()
  2.     With Range("a3:a100")
  3.         Range("a3").Activate
  4.         .FormatConditions.Delete
  5.         .FormatConditions.Add Type:=xlExpression, Formula1:="=LEN(A3)>0"
  6.         .FormatConditions(1).SetFirstPriority
  7.         With .FormatConditions(1).Interior
  8.             .PatternColorIndex = xlAutomatic
  9.             .Color = 255
  10.             .TintAndShade = 0
  11.         End With
  12.     End With
  13. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2013-5-23 16:39 | 显示全部楼层
hwc2ycy 发表于 2013-5-23 16:23

非常感谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 17:48 , Processed in 0.296167 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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