简体   繁体   中英

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.

What I want to do is when the team appears in the cell is for excel to display the appropriate graph for that team.

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.

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. Looking at the Object Model Reference section , you'll find many Chart-like objects that you can manipulate to make your project work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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