首页officeexcel正文

如何让excel图表形状生动起来

强国说学习2022-09-1885excel公式excel图表excel技巧Excel教程

下面再举一个例子,如下图1所示。

图1

对单元格H3设置数据有效性如下图2所示。

由强国说学习-WPS之家(wps.qiangguoshuo.com)收集的该篇文章内容来源于网络,希望能为广大朋友提供帮助。

图2

在形状所在的工作表模块中,输入代码:

Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo errHandler Dim sh As Shape Dim myColor As Long Dim lAdj As Long Set sh = Shapes(“Partial Circle 1”) If Target.Address = “$H$3″ Then Application.EnableEvents = False sh.Adjustments.Item(1) = 0 Select Case Target.Value Case 0: lAdj = 0 Case Else: lAdj = -(360 – (360 * Target.Value)) End Select sh.Adjustments.Item(2) = lAdj ‘修改形状颜色 Select Case Target.Value Case Is >= 0.85: myColor _ = RGB(169, 208, 142) ‘绿色 Case Is >= 0.75: myColor _ = RGB(255, 255, 0) ‘黄色 Case Is >= 0.5: myColor _ = RGB(255, 192, 0) ‘橙色 Case Else: myColor _ = RGB(255, 0, 0) ‘红色 End Select sh.Fill.ForeColor.RGB = myColor End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: MsgBox Err.Number & ” ” &Err.Description GoTo exitHandlerEnd Sub

我们可以添加一小段代码,让这个图动起来,如下图3所示。

图3

如想转载该文章请注明出处:强国说学习-qiangguoshuo.com
强国说学习

转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!

本文链接:https://www.qiangguoshuo.com/excel/21370.html