我正在为Excel电子表格中的每一行数据创建一个新图表。我让Vbasic正常工作,但我想更改每行添加的工作表上的图表位置。
以下是我的代码,我需要做些什么才能自动更改页面上图表的位置?理想情况下,我希望它位于每张纸的左上角。
Sub DrawCharts()
Dim Ws As Worksheet
Dim NewWs As Worksheet
Dim cht As Chart
Dim LastRow As Long
Dim CurrRow As Long
Set Ws = ThisWorkbook.Worksheets("Sheet1")
LastRow = Ws.Range("A65536").End(xlUp).Row
For CurrRow = 2 To LastRow
Set NewWs = ThisWorkbook.Worksheets.Add
NewWs.Name = Ws.Range("A" & CurrRow).Value
Set cht = ThisWorkbook.Charts.Add
With cht
.ChartType = xl3DColumnClustered
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = "=" & Ws.Name & "!R" & CurrRow & "C3:R" & CurrRow & "C8"
.SeriesCollection(1).Name = "=" & Ws.Name & "!R" & CurrRow & "C2"
.SeriesCollection(1).XValues = "Sheet1!R1C3:R1C8"
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 1
.Axes(xlValue).MajorUnit = 0.2
.SetElement (msoElementDataLabelShow)
.SetElement (msoElementLegendNone)
.Location Where:=xlLocationAsObject, Name:=NewWs.Name
End With
Next CurrRow
End Sub
感谢任何帮助。
答案 0 :(得分:0)
之后
.Location
这一行:
.Left = 0
.Top = 0
您也可以尝试
.PlotArea.Left = 0
.PlotArea.Top = 0
它可能会略有不同。