热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

确定ExcelVBA中的点的值-DeterminingthevalueofapointinExcelVBA

Iamtryingtohavethepointsinachartchangecoloriftheyarewithincertainvalueparamaters(

I am trying to have the points in a chart change color if they are within certain value paramaters (i.e., >1 is green, <1 is red, anything else is blue). I cannot determine how to get VBA to give me the value of any given point.

如果它们在某些值参数范围内(即> 1为绿色,<1为红色,其他任何为蓝色),我试图让图表中的点改变颜色。我无法确定如何让VBA给我任何给定点的价值。

In this thread, previously answered, the answer (very helpful in other ways) indicates that points(num).value will return the value at the point. However, I am getting an error message doing this, and nowhere else online or in the VBA help can I find a method that corresponds to this. Has anyone else had any success with this?

在此线程中,先前已回答,答案(在其他方面非常有用)表示点(num).value将返回该点的值。但是,我收到一条错误消息,并且在其他任何地方在线或在VBA帮助中我都可以找到与此对应的方法。有没有人有这个成功?

Here's the snippet of code giving me trouble:

这是代码片段给我带来的麻烦:

For Count = 1 To 7
    If Worksheets("Sheet1").ChartObjects("ChartName").Chart.SeriesCollection(1).Points(Count).Value > 1 Then
    '... do stuff

Because of the way the data are stored in the dataset, it would definitely be better to get the value from the chart directly. I could figure out a workaround using the dataset itself, but I would rather avoid that.

由于数据存储在数据集中的方式,从图表中直接获取值肯定会更好。我可以使用数据集本身找出解决方法,但我宁愿避免这种情况。

1 个解决方案

#1


10  

Sub Tester()

Dim cht As Chart, s As Series, p As Point
Dim vals, x As Integer

    Set cht = ActiveSheet.ChartObjects(1).Chart
    Set s = cht.SeriesCollection(1)

    vals = s.Values

    For x = LBound(vals) To UBound(vals)
      If vals(x) > 10 Then
        With s.Points(x)
            .MarkerBackgroundColor = RGB(255, 0, 0)
            .MarkerForegroundColor = RGB(255, 0, 0)
        End With
      End If
    Next x

End Sub

推荐阅读
author-avatar
juxiu小妹_895
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有