通过vba代码从Excel图表中取消选择空的特定水平轴标签

时间:2016-09-09 11:58:06

标签: excel-vba vba excel

我有一个Excel条形图,带有水平轴标签。某些标题标签为空白,如图所示。我如何从轴标签中取消选择这些标签,以便它们不会通过vba代码显示在图表中。

谢谢你,非常感谢你的帮助...... enter image description here

1 个答案:

答案 0 :(得分:0)

我只是通过根据所需的特定单元构建Chart CollectionSeries XValues和Values字符串来避免整个取消选择。避免空白的空单元格。

Dim chartPhaseXValues As String
Dim chartDurationValues As String
'For Loop Here
chartPhaseXValues = chartPhaseXValues & oExcel.ActiveSheet.Name & "!" & _
                    oExcel.Range("A1").Offset(rowCount, 1).Address & ","
hartDurationValues = chartDurationValues & oExcel.ActiveSheet.Name & "!" & _
                     oExcel.Range("A1").Offset(rowCount, 4).Address & ","
'End For Loop

' Remove the trailing , at the end of each string
chartPhaseXValues = Left(chartPhaseXValues, Len(chartPhaseXValues) - 1)
chartDurationValues = Left(chartDurationValues, Len(chartDurationValues) - 1)

' Add the Series to the graph
oExcel.ActiveChart.SeriesCollection.NewSeries
oExcel.ActiveChart.FullSeriesCollection(1).Name = "=""StartDate"""
oExcel.ActiveChart.FullSeriesCollection(1).Values = "=" & chartDurationValues
oExcel.ActiveChart.FullSeriesCollection(1).XValues = "=" & chartPhaseXValues