是否真的可以为每第n行绘制excel vba图

时间:2017-12-11 11:16:25

标签: excel vba excel-vba plot

所以我有一个有超过8000行的excel文件,我必须绘制一个基于B2到B8000和C2到C8000的xlscatter图。但绘制图表所用的值必须使用每50个单元格,我发现了类似的问题How to Use Every nth Cell in a Chart in Excel Programmatically。但是给出的代码没有绘制图形,它只是一个空白图形。对此有什么解决方案吗?

[...]

Dim xS As String

Dim yS As String

xS = "="

yS = "="

For i = 1 To 23000 step 50

    If i > 1 Then

        xS = xS & ","

        yS = yS & ","

    End If

    xS = xS & "A!$A$" & CStr(i)

    yS = yS & "A!$B$" & CStr(i)

Next

ActiveChart.FullSeriesCollection(1).XValues = xS

ActiveChart.FullSeriesCollection(1).Values = yS

[...]

我试过的那个

1 个答案:

答案 0 :(得分:0)

首先是来自Sheet的数据叫做A?如果没有那么你的代码需要改变:

xS = xS & "A!$A$" & CStr(i)
yS = yS & "A!$B$" & CStr(i)

要:

xS = xS & "Sheet1!$A$" & CStr(i) 'Where Sheet1 is your Sheet name.
yS = yS & "Sheet1!$B$" & CStr(i)

此外,我非常确定你应该删除以下几行:

xS = "="
yS = "="