如何使用Excel VBA更改水平(类别)轴标签

如何使用Excel VBA更改水平(类别)轴标签,excel,vba,Excel,Vba,我需要使用数组更改或自定义添加带有宏的水平(类别)轴标签的帮助 我有以下数据(图1): 我想画一张这样的图表(图2): 我可以用宏绘制类似的XY散点图,但标签错误。使用宏创建的图表如下(图3): 我用以下VBA宏代码绘制了图表: Sub plot_test3() Dim ws2 As Worksheet Dim i, j, c, m, n, a, lrow As Long Dim frist_code, frist_value, frist_name As Variant Dim xyc

我需要使用数组更改或自定义添加带有宏的水平(类别)轴标签的帮助

我有以下数据(图1):

我想画一张这样的图表(图2):

我可以用宏绘制类似的XY散点图,但标签错误。使用宏创建的图表如下(图3):

我用以下VBA宏代码绘制了图表:

Sub plot_test3()

Dim ws2 As Worksheet
Dim i, j, c, m, n, a, lrow As Long
Dim frist_code, frist_value, frist_name As Variant
Dim xychart As Chart

Set ws2 = Worksheets("Sheet2")

i = 1: j = 1: a = 1
c = 4: lrow = 6: m = 2: n = 2

ws2.Activate

ReDim frist_code(i To lrow - 1, j To c)
ReDim frist_value(i To lrow - 1, j To c)
ReDim frist_name(i To lrow - 1, j To c)

For i = 1 To lrow - 1
    For j = 1 To c
        frist_value(i, j) = ws2.Cells(m, n)
        frist_code(i, j) = j
        frist_name(i, j) = ws2.Cells(1, n)
        n = n + 1
    Next j
    n = 2
    m = m + 1
Next i

Set xychart = ws2.Shapes.AddChart2(332, xlXYScatter, Left:=0, Top:=0, Width:=400, Height:=300).Chart

For i = 1 To lrow - 1
    For j = 1 To c
        xychart.SeriesCollection.NewSeries
    
        With xychart.SeriesCollection(a)
            .name = frist_name(i, j)
            .Values = frist_value(i, j)
            .XValues = frist_code(i, j)    'most probably, the mistake is here
            .MarkerSize = 15
        End With
        a = a + 1
    Next j
    j = 1
Next i

xychart.Axes(xlCategory).TickLabelPosition = xlLow

End Sub
我希望将水平轴标签重命名为A、B、C、D(如图2所示),而不是在VBA宏中使用数组来使用1、2、3、4。

如果有人能够解决我的VBA宏中的这个问题或错误,那将非常有帮助。。谢谢