我有一个图表,它在我运行代码后会改变输入。
Sub copy_values_for_chart()
With Worksheets("Working")
'clear chart consolidated data
LastRow = FindLastRow("Working")
.Range("Y4:AE" & LastRow).Clear
LastRow = FindLastRow("Working")
'copy Eolus T-1 data
.Range("Q4:W4").Copy
.Range("Y4").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
'.Range("Q3").Value = "Date"
'calculate worst case P&L into col O
For Line = 4 To LastRow
If Range("O" & Line - 1).Value <> "" Then
Range("o" & Line).Value = Application.WorksheetFunction.Min(Range("J" & Line & ":" & "N" & Line))
End If
Next Line
'append rage data
.Range("I4:O" & LastRow).Copy
.Range("Y5").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
'append copy of static data
.Range("A4 : G" & LastRow).Copy
LastRow = FindLastRow("Working")
.Range("Y" & LastRow + 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
'sort consolidated data by date asc
LastRow = FindLastRow("Working")
.Range("Y3:AE" & LastRow).Sort key1:=Worksheets("Working").Range("Y3"), order1:=xlDescending, Header:=xlYes
'Application.CutCopyMode = False
End With
'update chart range data
Set DataRange = Worksheets("Working").Range("Y3 : AE" & LastRow) 'Change last row to number to include.
Worksheets("sheet1").ChartObjects("Chart 1").Chart.SetSourceData Source:=DataRange
End Sub
运行之前,左侧有 6 列,右侧有数据。
运行代码后,左侧显示 7 列,包括日期。
旧日期所在的位置在右侧以随机格式显示。
有人能帮助我保持代码运行后应有的状态吗?