本文介绍了在点击图表 - Excel VBA上获取X轴值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我遇到了一个奇怪的要求。我知道我们可以为图表分配一个宏。所以在方法上,可以创建图表的事件。 谢谢。 p> 解决方案如果您的图表在图表表中,您可以右键单击图表表选项卡,选择查看代码 选项显式 Private Sub Chart_Select(ByVal ElementID As long,ByVal Arg1 As Long,ByVal Arg2 As Long)选择案例ElementID 案例xlSeries 如果Arg2> 0 Then MsgBoxSeries& Arg1& vbCr& 点& Arg2 End If Case Else MsgBox Arg1& vbCr& Arg2 End Select End Sub 如果您的图表已嵌入工作表,那么您必须使用 WithEvents 作为@brettdj已经涵盖了此处 FOLLOWUP 这是您想要的吗? > Private Sub Chart_Select(ByVal ElementID As Long,ByVal Arg1 As Long,ByVal Arg2 As Long)选择案例ElementID case xlSeries 如果Arg2> 0 then x = ActiveChart.SeriesCollection(Arg1).XValues For i = LBound(x)To UBound(x)如果i = Arg2 then MsgBoxPoint: ; i& 和X Value =& x(i)退出对于结束如果下一个i 结束如果结束选择结束子 / p> I have come across a strange requirement.I know we can assign a macro to a chart. So in way, event for the chart can be created. But no idea of how to proceed further.Any idea to do this please?Thanks. 解决方案 If your Chart is in a Chart Sheet then you can right click on the Chart sheet tab, select "View code" and paste the following in its code module (see screenshot below)Option ExplicitPrivate Sub Chart_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long) Select Case ElementID Case xlSeries If Arg2 > 0 Then MsgBox "Series " & Arg1 & vbCr & "Point " & Arg2 End If Case Else MsgBox Arg1 & vbCr & Arg2 End SelectEnd SubIf your chart is embedded in a sheet then you will have to use WithEvents as @brettdj has already covered hereFOLLOWUPIs this what you are trying?Private Sub Chart_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long) Select Case ElementID Case xlSeries If Arg2 > 0 Then x = ActiveChart.SeriesCollection(Arg1).XValues For i = LBound(x) To UBound(x) If i = Arg2 Then MsgBox "Point :" & i & "and X Value = " & x(i) Exit For End If Next i End If End SelectEnd Sub 这篇关于在点击图表 - Excel VBA上获取X轴值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 22:15