使用range.find创建图表 - VBA

时间:2018-04-02 14:00:06

标签: excel vba excel-vba charts

enter image description here我有代码从userform文本框中搜索某个范围内的数字(包含合并单元格的A列),然后根据该数字创建一个图表。我在添加正确的轴值时遇到问题。根据找到的数字,它将创建一个图表,其中包含A列数字右侧的值。

Col A和B将是x轴,C,D,F将是y轴。

非常感谢任何帮助。

Private Sub CommandButton1_Click()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim ws As Worksheet: Set ws = Sheets("Trend")
Dim LastRow As Long, partnum As String, findpart As Range
Dim partChart As Chart
Dim chartWorkSheet As Worksheet

LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
partnum = TextBox1.Value


If Not Application.IsNA(Application.Match(partnum, Range("A:A"), 0)) Then
    Set findpart = Cells(Application.Match(partnum, Range("A:A"), 0), 1)

    ActiveWorkbook.Charts.Add

    With ActiveWorkbook.ActiveChart
        .ChartType = xlColumnClustered
        .SeriesCollection.NewSeries
        .SeriesCollection(1).Name = "QTY Left"
        .SeriesCollection(1).XValues = "Trend!"

'''                'Titles
'''                .HasTitle = True
'''                .ChartTitle.Characters.Text = "Scatter Chart"
'''                .Axes(xlCategory, xlPrimary).HasTitle = True
'''                .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text=*emphasized text*"X values"
'''                .Axes(xlValue, xlPrimary).HasTitle = True
'''                .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y values"
'''                .Axes(xlCategory).HasMajorGridlines = True
'''
'''                'Formatting
'''                .Axes(xlCategory).HasMinorGridlines = False
'''                .Axes(xlValue).HasMajorGridlines = True
'''                .Axes(xlValue).HasMinorGridlines = False
'''                .HasLegend = False
''
    End With
Else
    MsgBox ("Part Number Not Found!")
End If

Unload Me

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

0 个答案:

没有答案