ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 11162|回复: 21

技巧1——色彩缤纷的Data Bars

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-4-15 10:35 | 显示全部楼层 |阅读模式

Conditional Formatting Trick 1 – Multi-Coloured Data Bars
条件格式技巧1——色彩缤纷的Data Bars

A few months ago, I described the new features we have added to Excel 2007 in the area of conditional formatting.  One of the new formats we added is called a “data bar” … check out this earlier post for a refresher, but the basic idea is that Excel draws a bar in each cell representing the value of that cell relative to the other cells in the selected range.  Here is a shot from that post.
几个月以前,我讲述了在Excel 2007中新增加的有关条件格式的各种特性,其中之一就是我们称之为“data bar”的……可参阅以前的文章。但是我们只讲到最基础的概念,即在一个选定的区域里面,由Excel根据不同单元格的数值对比情况,在每个单元格中绘制一个色带。下面是以前文章中的截图:

The Excel 2007 UI allows you to choose whatever colour you want for your data bars, but, by default, all the data bars you apply to a range have to be the same colour.  Someone on our team recently showed me how to use a tiny bit of VBA to simulate having multiple colours of data bars on a range conditionally applied, so I thought I would pass along the trick.
Excel 2007允许你为你的data bars选择任何你想要的颜色,但是,默认情况下,同一区域中的data bars,只能有同一种颜色。最近,开发团队中的某位成员向我展示了如何在同一区域中创建多种颜色的data bars,只需要利用非常简单的VBA代码即可。所以,我想我应该好好发挥这个技巧的威力。
Say, for example, you are looking at student grades, and you want all the data bars for students with a passing mark (60%+ and above) to be green, and those with a failing grade (59% or less) to be red.  The first thing you would do is to add some red data bars to your data, and then some green data bars.  By default, Excel shows you the last set applied, so the data bars would be green.  If you then launch the VB Editor (Alt + F11) and in the immediate window (Ctrl+G), type:
selection.FormatConditions(1).formula = "=if(c3>59, true, false)"
You would see that your data now looks like this, which makes it easy to spot the failing grades.

举个例子,你正在考虑为学生评分,你希望当学生成绩及格(60%或更高)时,data bars是绿色的,而不合格的成绩(59%或更低)对应的data bars是红色的。第一步,你肯定会为你的数据加上一些红色的data bars,然后是绿色的。在默认情况下,Excel只接受你最后的设置,所以所有的data bars都将是绿色的。如果你现在打开VB编辑器(Alt + F11),在立即窗口(Ctrl+G)中输入:selection.FormatConditions(1).formula = "=if(c3>59, true, false)"
你将会看到你的数据就会像下面这样,非常容易的辨识出不合格的成绩:

So how does this work?  Every conditional format has a Formula property, which allows you to specify a formula which determines whether the conditional format is visible.  In this case, we are simply saying that the green data bars (the most recent ones) should only be visible if a value is greater than 59.
This property is available on all conditional formats, so I expect that users will find all sorts of creative uses beyond just this case.

那么这项工作是如何完成的?原来,每一个条件格式都有一个公式的属性,此属性允许你指定一个公式来判断其本身是否可见。在这个例子中,我们简单的指定为,只有单元格数值大于59时,绿色的data bars才会被显示。
所有的条件格式都可以利用这个属性,因此,我希望用户能够发挥创造力,举一反三。

Published Friday, February 24, 2006 1:32 PM by David Gainer

注:本文翻译自http://blogs.msdn.com/excel ,原文作者为David Gainera Microsoft employee)Excel Home 授权转载。严禁任何人以任何形式转载,违者必究。

[此贴子已经被作者于2006-6-27 14:24:44编辑过]

技巧1——色彩缤纷的Data Bars

技巧1——色彩缤纷的Data Bars

TA的精华主题

TA的得分主题

发表于 2006-4-15 11:24 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-4-16 20:20 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
期待中……

TA的精华主题

TA的得分主题

发表于 2006-6-23 14:46 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
照着做没试出来……

TA的精华主题

TA的得分主题

发表于 2006-6-24 17:50 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-6-24 20:41 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
好啊,很漂亮,明天试试

TA的精华主题

TA的得分主题

发表于 2006-6-26 09:20 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-7-16 22:29 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-7-24 11:05 | 显示全部楼层

能否纯按自己的意愿设计条件?

TA的精华主题

TA的得分主题

发表于 2006-7-29 08:26 | 显示全部楼层

按照楼主的方法做了,没做出来,这是咋回事呀。

楼主或会的朋友传个操作图片上来吧,很想学呀

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

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-27 16:23 , Processed in 0.043458 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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