Hi. This doesen't make any sence to me, but when I am using
ActiveWorkbook.Sheets(cur_sheet).Shapes.AddChart.Select
this plot is taking random data.
Please take a look at whole section, I marked in red row, where scatter is being made and select random data(at least it seemes random to me):
Public Sub draw_grath(dCell_1 As Range, dCell_2 As Range, aCell_1 As Range, sheet_count() As String, cur_sheet As String, dTitle As Range, ox_title As String, oy_title As String)
Dim a As Range, b As Range
ActiveWorkbook.Sheets(cur_sheet).Shapes.AddChart.Select
ActiveWorkbook.ActiveChart.ChartType = xlXYScatter
Dim i As Integer, n As Integer, skip As Integer
Set a = dCell_1
skip = 0
n = 1
For i = 1 To UBound(sheet_count)
Do Until n < 0
If Not IsEmpty(ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dCell_1.Address).Cells(n, 1)) Then
Set a = Range(ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dCell_1.Address).Cells(n, 1).Address)
n = n + 1
Else: Exit Do
End If
Loop
If IsEmpty(ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dCell_1.Address)) Then
skip = skip + 1
ElseIf Not (a.Row - dCell_1.Row = 0) Then
ActiveWorkbook.ActiveChart.SeriesCollection.NewSeries
ActiveWorkbook.ActiveChart.SeriesCollection(i - skip).Name = ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dTitle.Address).Value
ActiveWorkbook.ActiveChart.SeriesCollection(i - skip).XValues = ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dCell_1.Address, a.Address)
Set b = Range(Cells(a.Row, dCell_2.Column).Address)
ActiveWorkbook.ActiveChart.SeriesCollection(i - skip).Values = ActiveWorkbook.Sheets(CInt(sheet_count(i - 1))).Range(dCell_2.Address, b.Address)
Else: skip = skip + 1
End If
Set b = Nothing
Set a = Nothing
n = 1
Next
Do Until n < 0
If Not IsEmpty(aCell_1.Cells(n, 1)) Then
Set a = Range(aCell_1.Cells(n, 1).Address)
n = n + 1
Else: Exit Do
End If
Loop
With ActiveWorkbook.ActiveChart
.SeriesCollection.NewSeries
.SeriesCollection(i - skip).Name = "Aproximation"
.SeriesCollection(i - skip).XValues = Range(aCell_1.Address, a.Address)
.SeriesCollection(i - skip).Values = Range(aCell_1.Offset(0, 1).Address, a.Offset(0, 1).Address)
.ChartType = xlXYScatterLinesNoMarkers
.Location Where:=xlLocationAsObject, Name:=aCell_1.Parent.Name
.HasTitle = True
.ChartTitle.Characters.Text = "Square X"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = ox_title
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = oy_title
.Axes(xlCategory).HasMajorGridlines = False
.Axes(xlCategory).HasMinorGridlines = False
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlValue).HasMinorGridlines = False
.HasLegend = True
End With
End Sub
After end sub I have scatter with plots I need + several plots:untitled.jpg
Please help with any ideas!
Bookmarks