为什么我的图表在excel 2013自动更新,每当我添加额外的数据?

我还是VBA的新手,因此我对VBA没有多less了解。 关于这个问题,我在网上search了它,并尝试了堆栈溢出的大多数给定的解决scheme,仍然无法使其工作。 唯一的方法就是每天手动做这个工作,我不希望这样做。 每天我都会将数据添加到工作表中为我生成一个比较图表。 我试过使用各种方法: – chart.refresh – 做事件 – refreshall

可悲的是,他们都没有为我的工作簿工作。 除此之外,我有2个图表需要在工作表中更新,我有3个工作表。 所以我会马上更新6个图表。 有没有办法使它的工作,而不是手动?

第一张图片中突出显示的区域是左侧的图表

第二张图中的高亮区域是右侧的图表

这是我正在工作的代码,更新图表已经是最后一部分了。

Sub trial() Dim wb As Workbook, wb2 As Workbook, wb3 As Workbook Dim ws As Worksheet Dim fn As String Set wb = ActiveWorkbook Set ws = Sheets.Add(After:=Sheets(Worksheets.Count)) Dim Ret Ret = Application.GetOpenFilename("Lkl Files (*.lkl), *.lkl") If Ret <> False Then With ActiveSheet.QueryTables.Add(Connection:= _ "TEXT;" & Ret, Destination:=Range("$A$1")) .Name = "SPC_PLTB_450B_12092107_25°C_CW" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 65001 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = False .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) .TextFileDecimalSeparator = "," .TextFileThousandsSeparator = "." .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With End If Sheets(2).Activate 'this is for the date (loop) Dim FirstCell As String Dim i As Integer FirstCell = "C19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop ActiveCell = Format(Date, "mm/dd/yyyy") ws.Activate ws.AutoFilterMode = False ws.Range("$A$9:$P$417").AutoFilter Field:=5, Criteria1:= _ "1" Range("F31:F401").Select Selection.Copy Sheets(2).Activate 'this is for the raw data FirstCell = "D19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=True Sheets(3).Activate FirstCell = "C19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop ActiveCell = Format(Date, "mm/dd/yyyy") ws.Activate Range("D31:D401").Select Application.CutCopyMode = False Selection.Copy Sheets(3).Activate FirstCell = "D19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=True Sheets(4).Activate FirstCell = "C19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop ActiveCell = Format(Date, "mm/dd/yyyy") ws.Activate Range("G31:G401").Select Application.CutCopyMode = False Selection.Copy Sheets(4).Activate FirstCell = "D19" Range(FirstCell).Select Do Until ActiveCell.Value = "" If ActiveCell.Value = "" Then Exit Do Else ActiveCell.Offset(1, 0).Select End If Loop Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=True Worksheets(5).Delete End Sub