从图表中仅删除 0 个值 Excel

Remove just 0 values from Chart Excel

我一直在尝试从 Excel 图表中删除这些 0 我已经观看了多个使用 Format Control #,##0;-#,##0;;. 的视频以及 Google 上可用的不同内容,但没有任何反应。我已将 0 值替换为 Nothing#.

去前进取消勾选Show a zero in cells that have zero values 然后转到 Select 数据源 => 隐藏和空单元格,但仍然没有任何反应。

问题仍然没有解决,有人可以帮我解决这个问题吗?我将非常感谢你的帮助。

如果可以通过VBA解决,请分享代码或手动解决。

我试过写记录代码,但我真的不知道该怎么做。

Sub Macro1()
'
' Macro1 Macro
'

'
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(3).Select
    ActiveChart.SetElement (msoElementDataLabelCenter)
    ActiveChart.FullSeriesCollection(3).DataLabels.Select
    ActiveChart.FullSeriesCollection(3).Points(1).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(3).DataLabels.Select
    ActiveChart.FullSeriesCollection(3).Points(9).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(1).Select
    ActiveChart.SetElement (msoElementDataLabelCenter)
    ActiveChart.FullSeriesCollection(1).DataLabels.Select
    ActiveChart.FullSeriesCollection(1).Points(9).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(2).Select
    ActiveChart.SetElement (msoElementDataLabelCenter)
    ActiveChart.FullSeriesCollection(2).DataLabels.Select
    ActiveChart.PlotArea.Select
    ActiveChart.FullSeriesCollection(2).DataLabels.Select
    ActiveChart.FullSeriesCollection(2).Points(9).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(2).DataLabels.Select
    ActiveChart.FullSeriesCollection(2).Points(8).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(2).DataLabels.Select
    ActiveChart.FullSeriesCollection(2).Points(6).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(2).DataLabels.Select
    ActiveChart.FullSeriesCollection(2).Points(5).DataLabel.Select
    Selection.Delete
    ActiveSheet.ChartObjects("Chart 16").Activate
    ActiveChart.FullSeriesCollection(3).DataLabels.Select
    ActiveChart.ChartArea.Select
End Sub

我试过这个,但它删除了所有标签而不是 0。

Sub chartth()

Sheet5.ChartObjects("Chart 16").Activate

With ActiveChart.SeriesCollection(1)
    For i = 1 To .Points.Count
        If .Points(i).HasDataLabel = False Then
            .Points(i).Select
            ActiveChart.SetElement (msoElementDataLabelShow)
                If .Points(i).DataLabel.Text = 0 Then
                    .Points(i).HasDataLabel = False
                    .Points(i).DataLabel.ShowValue = False
                End If
        ElseIf .Points(i).DataLabel.Text = 0 Then
            .Points(i).HasDataLabel = False
            .Points(i).DataLabel.ShowValue = False
        End If
    Next i
End With

With ActiveChart.SeriesCollection(2)
    For i = 1 To .Points.Count
        If .Points(i).HasDataLabel = False Then
            .Points(i).Select
            ActiveChart.SetElement (msoElementDataLabelShow)
                If .Points(i).DataLabel.Text = 0 Then
                    .Points(i).HasDataLabel = False
                    .Points(i).DataLabel.ShowValue = False
                End If
        ElseIf .Points(i).DataLabel.Text = 0 Then
            .Points(i).HasDataLabel = False
            .Points(i).DataLabel.ShowValue = False
        End If
    Next i
End With


With ActiveChart.SeriesCollection(3)
    For i = 1 To .Points.Count
        If .Points(i).HasDataLabel = False Then
            .Points(i).Select
            ActiveChart.SetElement (msoElementDataLabelShow)
                If .Points(i).DataLabel.Text = 0 Then
                    .Points(i).HasDataLabel = False
                    .Points(i).DataLabel.ShowValue = False
                End If
        ElseIf .Points(i).DataLabel.Text = 0 Then
            .Points(i).HasDataLabel = False
            .Points(i).DataLabel.ShowValue = False
        End If
    Next i
End With

也许尝试类似下面的方法,它将数据标签应用到每个 Series,然后循环遍历每个 Series 中的 Point 并删除 DataLabel 如果这是 0.

Sub ApplyLabelsAndClearZeros(ByVal chrt As Chart)
    Dim ser As Series
    For Each ser In chrt.SeriesCollection
        ser.ApplyDataLabels
        
        Dim pnt As Point
        For Each pnt In ser.Points       
            If pnt.DataLabel.Text = "0" Then
                pnt.HasDataLabel = False
            End If          
        Next
    Next
End Sub

像下面这样调用它:

Sub Test()
    ApplyLabelsAndClearZeros Sheet1.ChartObjects(1).Chart
End Sub