简体   繁体   English

使用if语句或vba在Excel中满足某些条件时显示图形

[英]Displaying graphs when certain criteria is met in Excel using if statements or vba

I'm creating a project where an individual's performance is charted then compared against their team's performance. 我正在创建一个项目,在该项目中将个人绩效绘制成图表,然后与团队绩效进行比较。

Unfortunately, due to my company's policy, I'm not allowed to take the document off of the network nor post any details online so my description is all I have unfortunately. 不幸的是,由于我公司的政策,我不允许将文档从网络上删除或在线发布任何详细信息,所以很遗憾,我的描述仅是我的所有。

The user is selected from a drop down created using data validation calling the usernames from another sheet. 从使用数据验证从另一个工作表调用用户名创建的下拉列表中选择用户。 Then using INDEX and MATCH in the adjoining cell depending on the user selected shows their team they are attached to. 然后根据所选择的用户,在相邻的单元格中使用INDEX和MATCH来显示其所属的团队。

What I want to do is when the team appears in the cell is for excel to display the appropriate graph for that team. 我想做的是,当团队出现在单元格中时,Excel会为该团队显示适当的图形。

Any suggestions on how to do this? 有关如何执行此操作的任何建议?

You have several options to have these charts show when an individual is selected. 您有几个选项可以使这些图表在选定个人时显示。 For example, a macro could be assigned to a keystroke so a certain key combination is pressed after selecting the individual. 例如,可以将一个宏分配给一个击键,因此在选择个人之后按下某个键组合。 You could also place a button or shape near the vicinity of the cell that activates a macro. 您还可以在激活宏的单元格附近放置一个按钮或形状。 Or you could use the Worksheet_Change subroutine, which runs (as you've guessed) any time the worksheet is changed. 或者,您可以使用Worksheet_Change子例程,该子例程会在工作表更改时运行(正如您所猜测的)。

From there, you'd need to write code that displays the appropriate charts. 从那里,您需要编写显示适当图表的代码。 The easiest way to start on this would be to record a macro while you create charts that look like what you'd want. 最简单的方法是在创建看起来像您想要的图表时记录宏。 Then you can edit the code in the macro to fit your particular situation. 然后,您可以在宏中编辑代码以适合您的特定情况。

When looking at this macro, I'd suggest paying special attention to where the charts pull information from. 在查看此宏时,建议您特别注意图表从中获取信息的位置。 If this is not correct for when you run the macro in the future, the charts won't be correct. 如果以后运行宏不正确,则图表将不正确。

Lastly, as you work on editing the macro, you might consider adding code to delete any charts that were previously displayed. 最后,在编辑宏时,您可以考虑添加代码以删除以前显示的任何图表。

For reference you can always choose "Help" from the VBA editor or press F1. 作为参考,您始终可以从VBA编辑器中选择“帮助”或按F1。 Looking at the Object Model Reference section , you'll find many Chart-like objects that you can manipulate to make your project work. 查看“ 对象模型参考”部分 ,您将找到许多类似于Chart的对象,可以对其进行操作以使项目正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM