Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 使用VBA创建包含多个系列的xy散点图_Excel_Vba - Fatal编程技术网

Excel 使用VBA创建包含多个系列的xy散点图

Excel 使用VBA创建包含多个系列的xy散点图,excel,vba,Excel,Vba,您好,我正在尝试创建包含多个系列的xy散点图。我必须为每个系列选择从D列开始的第8列作为x轴值,从H列开始的第8列作为y轴值。必须在工作表中填写(带值)的列数结束前完成此操作。 我试着编写代码,但这似乎不起作用。非常感谢您的帮助,因为我将不得不为许多纸张和文件这样做。。 代码如下。 多谢各位 Sub Macro2() Dim ws As Worksheet Dim i As Integer Dim j As Integer Dim ws_count As Integer Dim cht

您好,我正在尝试创建包含多个系列的xy散点图。我必须为每个系列选择从D列开始的第8列作为x轴值,从H列开始的第8列作为y轴值。必须在工作表中填写(带值)的列数结束前完成此操作。 我试着编写代码,但这似乎不起作用。非常感谢您的帮助,因为我将不得不为许多纸张和文件这样做。。 代码如下。 多谢各位

    Sub Macro2()
Dim ws As Worksheet
Dim i As Integer
Dim j As Integer
Dim ws_count As Integer
Dim cht As Chart
Dim lCol As Long
Dim lRow As Long
Dim chtobjt As ChartObject
Dim rngChtData As Range
Dim rngChtXVal As Range
Dim xval As Range
Dim yval As Range
ws_count = ThisWorkbook.Worksheets.Count
MsgBox ("Total number of sheets" & ws_count)
For Each ws In ThisWorkbook.Worksheets
    'Find the last non-blank cell in column A(1)
    lRow = ws.Cells(Rows.Count, 5).End(xlUp).Row
    
    'Find the last non-blank cell in row 1
    lCol = ws.Cells(5, Columns.Count).End(xlToLeft).Column

    MsgBox "Last Row: " & lRow & vbNewLine & _
            "Last Column: " & Columns(lCol).Address(False, False)
    MsgBox (lCol)
       
    ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers).Select
    MsgBox (ActiveChart.Name)
    i = 4
    j = 1
    For i = 4 To lCol Step 8
    a = ws.Cells(5, i).Address
    a1 = ws.Cells(lRow, i).Address
    b1 = ws.Cells(lRow, i + 4).Address
    b = ws.Cells(5, i + 2).Address
    With ActiveChart.ChartArea
    .SeriesCollection.NewSeries
    .FullSeriesCollection(j).XValues = "=" & ws.Range(a, a1)
    .FullSeriesCollection(j).Values = "=" & ws.Range(b, b1)

    End With
    j = j + 1
    Next i
        
    i = i + 8
    
 Next



End Sub

代码被正确粘贴。。。代码从请求描述的正文开始。如果您在步骤8中使用For循环,则不需要
i=i+8