VBA泡泡图

时间:2017-09-09 14:44:16

标签: excel vba excel-vba excel-2010

我有四列由几行组成。有些是充满信息的,有些是空的,如下所示。

 w     x     y   z
Blue   23   74   120
White  50   25   34
Grey   11   45   
Yellow 25   12   12
Black  11   22 

我要做的是让每一行代表一个'泡沫'在bubble excel图中。气泡的大小将等于z。 感谢Tom Hollander,我找到了一种方法来管理它,我调整了代码来制作我想要的东西,找到Tom的下面一个。这里每个泡泡代表一个系列,所以有自己的标签。我现在唯一的问题是,我想告诉我的代码不要创建气泡,即当Z轴为空时不要创建标签。

有什么想法吗?

我也在尝试按照泡沫顺序找到标签订单的方法,即最高的泡泡将首先标记等等......

Public Sub CreateMultiSeriesBubbleChart()
    If (selection.Columns.Count <> 4 Or selection.Rows.Count < 3) Then
        MsgBox "Selection must have 4 columns and at least 2 rows"
        Exit Sub
    End If

    Dim bubbleChart As ChartObject
    Set bubbleChart = ActiveSheet.ChartObjects.Add(Left:=selection.Left, 
Width:=600, Top:=selection.Top, Height:=400)
    bubbleChart.chart.ChartType = xlBubble
    Dim r As Integer
    For r = 2 To selection.Rows.Count
        With bubbleChart.chart.SeriesCollection.NewSeries
            .Name = "=" & selection.Cells(r, 1).Address(External:=True)
            .XValues = selection.Cells(r, 2).Address(External:=True)
            .Values = selection.Cells(r, 3).Address(External:=True)
            .BubbleSizes = selection.Cells(r, 4).Address(External:=True)
        End With

    Next

    bubbleChart.chart.SetElement 
(msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
    bubbleChart.chart.Axes(xlCategory, xlPrimary).AxisTitle.Text = "=" & 
selection.Cells(1, 2).Address(External:=True)

    bubbleChart.chart.SetElement (msoElementPrimaryValueAxisTitleRotated)
    bubbleChart.chart.Axes(xlValue, xlPrimary).AxisTitle.Text = "=" & 
selection.Cells(1, 3).Address(External:=True)

    bubbleChart.chart.SetElement (msoElementPrimaryCategoryGridLinesMajor)
    bubbleChart.chart.Axes(xlCategory).MinimumScale = 0
End Sub

非常感谢您的任何帮助或帮助。

1 个答案:

答案 0 :(得分:2)

只需添加if语句。

DatabaseHandler
相关问题