''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim xRg As Range
Dim xChart As ChartObject
Set xRg = Range("A20:J50")
Set xChart = ActiveSheet.ChartObjects(1)
With xChart
.Top = xRg(1).Top
.Left = xRg(1).Left
.Width = xRg.Width
.Height = xRg.Height
End With
回復 2#jcchiang
第二個問題:如果我要畫第二張圖在同一張sheet內,應該怎麼寫(資料也是根據之前的sheet 但不同column)
因為不確定會畫幾張圖,所以程式會先詢問要畫幾次(如果只會畫2張就將y = Application.InputBox("畫圖次數", "")移除,For z = 1 To y改為For z = 1 To 2)
另外第二張以後的圖Column不知道會在哪裡,先當作再第一張圖Column往右擺放,如果位置差異較多就要再修改
Sub ALL_PLOT1()
Dim x, y, z As Integer
y = Application.InputBox("畫圖次數", "")
For z = 1 To y
Sheets("R2R_analysis").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
Application.ScreenUpdating = False
For x = 2 To Worksheets.Count
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(x - 1).Name = Sheets("工作表1 (" & x & ")").Range("U1").Offset(0, (z - 1))
ActiveChart.SeriesCollection(x - 1).XValues = Sheets("工作表1 (" & x & ")").Range("A2:A20000").Offset(0, (z - 1))
ActiveChart.SeriesCollection(x - 1).Values = Sheets("工作表1 (" & x & ")").Range("D2:D20000").Offset(0, (z - 1))
Next
Application.ScreenUpdating = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim xRg As Range
Dim xChart As ChartObject
Set xRg = Range("A20:J50")
Set xChart = ActiveSheet.ChartObjects(z)
With xChart
.Top = xRg(z).Top
.Left = xRg(z).Left
.Width = xRg.Width
.Height = xRg.Height
End With
Sub ALL_PLOT2()
Dim x, y, z, R As Integer
Dim CName(10, 10)
R = 0
Do While y = "" '防止資料為空白
y = Application.InputBox("畫圖次數", "", 1, 350, 150) '輸入要畫幾張圖,預設為1張
If y = "" Then MsgBox "畫圖次數不得為空白!!"
Loop
'----------------------------------輸入各圖表相關資料(所需資料自行增加)-----------
For z = 1 To y
Do While CName(z, 0) = ""
CName(z, 0) = Application.InputBox("第" & z & "圖名", "", "R2R_Ave.G.R." & z, 350, 150) '輸入圖表名稱,預設為R2R_Ave.G.R.1
If CName(z, 0) = "" Then MsgBox "請輸入圖名!!"
Loop
Do While CName(z, 1) = ""
CName(z, 1) = Application.InputBox("第" & z & "圖的MinimumScale", "", "0", 350, 150) '輸入x軸最小座標,預設為0
If CName(z, 1) = "" Then MsgBox "MinimumScale不得為空白!!"
Loop
Do While CName(z, 2) = ""
CName(z, 2) = Application.InputBox("第" & z & "圖的MaximumScale", "", "1000", 350, 150) '輸入x軸最大座標,預設為0
If CName(z, 2) = "" Then MsgBox "MaximumScale不得為空白!!"
Loop
Next
'---------------------------------------------------------------
For z = 1 To y
Sheets("R2R_analysis").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
Application.ScreenUpdating = False
For x = 2 To Worksheets.Count
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(x - 1).Name = Sheets("工作表1 (" & x & ")").Range("U1").Offset(0, (z - 1))
ActiveChart.SeriesCollection(x - 1).XValues = Sheets("工作表1 (" & x & ")").Range("A2:A20000").Offset(0, (z - 1))
ActiveChart.SeriesCollection(x - 1).Values = Sheets("工作表1 (" & x & ")").Range("D2:D20000").Offset(0, (z - 1))
Next
Application.ScreenUpdating = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim xRg As Range
Dim xChart As ChartObject
Set xRg = Range("A20:J50").Offset(0, R)
Set xChart = ActiveSheet.ChartObjects(z)
With xChart
.Top = xRg(z).Top
.Left = xRg(z).Left
.Width = xRg.Width
.Height = xRg.Height
End With