Excel精英培训网

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

[已解决]按条件填充颜色

[复制链接]
发表于 2015-1-3 11:47 | 显示全部楼层 |阅读模式
本帖最后由 left369 于 2015-1-3 16:08 编辑

按条件填充颜色
最佳答案
2015-1-3 15:24
  1. Sub Macro1()
  2. Dim arr, rng As Range, j%
  3. arr = Range("a16").CurrentRegion
  4. ActiveSheet.UsedRange.Interior.ColorIndex = xlNone
  5. For j = 1 To UBound(arr, 2)
  6.     s = Application.CountIf(Cells(16, j).Resize(4), arr(2, j))
  7.     If arr(2, j) = arr(3, j) And s = 2 Then
  8.         If rng Is Nothing Then
  9.             Set rng = Cells(17, j).Resize(2)
  10.         Else
  11.             Set rng = Union(rng, Cells(17, j).Resize(2))
  12.         End If
  13.     End If
  14. Next
  15. If Not rng Is Nothing Then rng.Interior.ColorIndex = 7
  16. End Sub
复制代码

笔.rar

8.26 KB, 下载次数: 18

发表于 2015-1-3 12:04 | 显示全部楼层
笔.rar (8.8 KB, 下载次数: 9)
回复

使用道具 举报

 楼主| 发表于 2015-1-3 12:16 | 显示全部楼层
qh8600 发表于 2015-1-3 12:04

不用格式,可以用代码么
回复

使用道具 举报

发表于 2015-1-3 12:25 | 显示全部楼层
选定16:19行,设置格式
=OR(AND(A$17=A$18,A$17=A$16),AND(A$17=A$18,A$17=A$19))
选定17:18行,设置格式
=(A$17=A$18)


笔.rar

4.12 KB, 下载次数: 2

回复

使用道具 举报

 楼主| 发表于 2015-1-3 13:17 | 显示全部楼层
有VBA的吗
回复

使用道具 举报

发表于 2015-1-3 15:24 | 显示全部楼层    本楼为最佳答案   
  1. Sub Macro1()
  2. Dim arr, rng As Range, j%
  3. arr = Range("a16").CurrentRegion
  4. ActiveSheet.UsedRange.Interior.ColorIndex = xlNone
  5. For j = 1 To UBound(arr, 2)
  6.     s = Application.CountIf(Cells(16, j).Resize(4), arr(2, j))
  7.     If arr(2, j) = arr(3, j) And s = 2 Then
  8.         If rng Is Nothing Then
  9.             Set rng = Cells(17, j).Resize(2)
  10.         Else
  11.             Set rng = Union(rng, Cells(17, j).Resize(2))
  12.         End If
  13.     End If
  14. Next
  15. If Not rng Is Nothing Then rng.Interior.ColorIndex = 7
  16. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 20:30 , Processed in 0.329136 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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