Hello,
I am trying to generate two xy plots of data from a different sheet. The problem is I can's resize and move them where I want
P.S. Sorry if it is a stupit question But I am a complete newbe
Sub graf()
' delete all graphs
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Dim xaxis As Range
Dim yaxis As Range
Dim extFFT As Chart
Dim intFFT As Chart
'PRINT graphs
Set extFFT = ActiveWorkbook.Charts.Add
Set extFFT = extFFT.Location(Where:=xlLocationAsObject, Name:="Sheet1")
With extFFT
.ChartType = xlXYScatterSmoothNoMarkers 'A scatter plot, not a line chart!
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Frequency"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "dB"
.HasLegend = False
.Axes(xlCategory).MajorUnit = 100000
' set other chart properties
End With
Set intFFT = ActiveWorkbook.Charts.Add
Set intFFT = intFFT.Location(Where:=xlLocationAsObject, Name:="Sheet1")
With intFFT
.ChartType = xlXYScatterSmoothNoMarkers 'A scatter plot, not a line chart!
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Frequency"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "dB"
.HasLegend = False
.Axes(xlCategory).MajorUnit = 100000
' set other chart properties
End With
'Put data in graphs
' 1st graph
Set xaxis = Range("Sheet2!D2:D8192")
Set yaxis = Range("Sheet2!E2:E8192")
Dim s1 As Series
Set s1 = extFFT.SeriesCollection.NewSeries
With s1
.Values = yaxis
.XValues = xaxis
' set other series properties
End With
'Resize graph////////THIS ONE WORKS
ActiveSheet.ChartObjects("Chart 1").Height = Range("C1:AA15").Height
ActiveSheet.ChartObjects("Chart 1").Width = Range("C1:AA15").Width
ActiveSheet.ChartObjects("Chart 1").Top = Range("C1:AA15").Top
ActiveSheet.ChartObjects("Chart 1").Left = Range("C1:AA15").Left
'Put data in graphs
' 2nd graph
Set xaxis = Range("Sheet2!D2:D8192")
Set yaxis = Range("Sheet2!F2:F8192")
Dim s2 As Series
Set s2 = intFFT.SeriesCollection.NewSeries
With s2
.Values = yaxis
.XValues = xaxis
' set other series properties
End With
'Resize graph////////IT RESIZES THE FIRST GRAPH AND I CAN'T SELECT THE SECOND GRAPH
ActiveSheet.ChartObjects("Chart 1").Height = Range("C16:AA30").Height
ActiveSheet.ChartObjects("Chart 1").Width = Range("C16:AA30").Width
ActiveSheet.ChartObjects("Chart 1").Top = Range("C16:AA30").Top
ActiveSheet.ChartObjects("Chart 1").Left = Range("C16:AA30").Left
End Sub
Bookmarks