Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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 2010 VBA-使用变量定义的范围更新图形_Vba_Excel - Fatal编程技术网

Excel 2010 VBA-使用变量定义的范围更新图形

Excel 2010 VBA-使用变量定义的范围更新图形,vba,excel,Vba,Excel,我有一张每天都在更新的Excel表格。我试图用每天添加的新数据(1行)自动更新图形 到目前为止,我已经: Sub UpdateGraphs() Dim latestRow As Integer Sheets("DailyJourneyProcessing").Select Range("A500").Select Do Until ActiveCell.Value = "" If ActiveCell.Value <> "" T

我有一张每天都在更新的Excel表格。我试图用每天添加的新数据(1行)自动更新图形

到目前为止,我已经:

Sub UpdateGraphs()

    Dim latestRow As Integer

    Sheets("DailyJourneyProcessing").Select

    Range("A500").Select

    Do Until ActiveCell.Value = ""
        If ActiveCell.Value <> "" Then
            ActiveCell.Offset(1, 0).Select
        End If
    Loop

    ActiveCell.Offset(-1, 0).Select
    Application.CutCopyMode = False
    ActiveCell.EntireRow.Copy

    ActiveCell.Offset(1, 0).Select
    ActiveCell.EntireRow.PasteSpecial (xlPasteAll)

    Application.CutCopyMode = False

    latestRow = ActiveCell.row

    Dim str1 As String
    Dim rng1 As Range

    str1 = "=DailyJourneyProcessing!$F$180:$F$" & latestRow
    Set rng1 = Range(str1)

    Debug.Print "Got this far..."

    Set ActiveChart.SeriesCollection(1).Values = Range(str1)
其中行号每天都在变化。这是我需要自动化的大约20个范围更新中的一个,但一旦我解决了其中一个,其他的应该是相同的

我已经尝试了所有我能在网上找到的东西,但没有什么效果

此时,我得到一个运行时错误91:Object或With block变量not set


任何帮助都将不胜感激。

实际上,VBA没有必要完成这项工作。您会发现该方法比VBA代码更易于管理和维护。另外,在不需要的时候最好不要使用VBA

然而,为了让您能够看到一种更有效的方法来编码您试图做的事情,我提供了下面的代码。它可能需要一些调整来适应您的实际数据集

Sub UpdateGraphs()

    Dim wks As Worksheet, rng1 As Range
    Dim latestRow As Long ' changed to long to handle rows over 32,000 (whatever number Integer stops at)

    Set wks = Sheets("DailyJourneyProcessing")

    With wks

        latestRow = .Range("F" & .Rows.Count).End(xlUp).Row

        str1 = "=DailyJourneyProcessing!$F$180:$F$" & latestRow

        Set rng1 = Range(str1)

        Dim myChart As Chart
        Set myChart = .ChartObjects("myChartName")

        myChart.SeriesCollection(1).Values = rng1

    End With

End Sub
Sub UpdateGraphs()

    Dim wks As Worksheet, rng1 As Range
    Dim latestRow As Long ' changed to long to handle rows over 32,000 (whatever number Integer stops at)

    Set wks = Sheets("DailyJourneyProcessing")

    With wks

        latestRow = .Range("F" & .Rows.Count).End(xlUp).Row

        str1 = "=DailyJourneyProcessing!$F$180:$F$" & latestRow

        Set rng1 = Range(str1)

        Dim myChart As Chart
        Set myChart = .ChartObjects("myChartName")

        myChart.SeriesCollection(1).Values = rng1

    End With

End Sub