I am trying to make a program which creates a scatter chart with specified axis titles. I initially tried to repurpose a recorded macro but I have tried many things but none of them seem to work. This is what I'm looking at right now. The first part is mostly unrelated, but I am not sure if it may be part of the issue, so it is included. I have also included stars next to the beginning of the area of interest. I am trying to get "time, s" into the x-axis, and "Theta, deg" into the y-axis. I am not a computer science degree, so please put the explaination in relatively simple terms if possible.
Dim i As Double
Dim CellCheck As Boolean
Dim CountPerMISSNUM(1048574) As Double
Dim A, B As Double
Dim C As String
Worksheets("taboutput_withplots").Select
Index = 1
CurrentMISSNUM = 1
CountPerMISSNUM(CurrentMISSNUM) = 0
Do While Index < 1048574
If IsEmpty(Cells(Index, 1).Value) = True Then
Exit Do
End If
If Index = 1 Then CountPerMISSNUM(CurrentMISSNUM) = CountPerMISSNUM(CurrentMISSNUM) + 1
If Index <> 1 And Cells(Index + 1, 1).Value = Cells(Index, 1).Value Then
CountPerMISSNUM(CurrentMISSNUM) = CountPerMISSNUM(CurrentMISSNUM) + 1
ElseIf Index <> 1 And Cells(Index + 1, 1).Value <> Cells(Index, 1).Value Then
If IsEmpty(Cells(Index + 1, 1).Value) = False Then
CurrentMISSNUM = CurrentMISSNUM + 1
Else
End If
End If
Index = Index + 1
Loop
ScatterIndex = 1
RowIndex = 0
InitialStartingIndex = 1
Do While ScatterIndex - 1 < CurrentMISSNUM
If ScatterIndex = 1 Then
RowIndex = RowIndex + CountPerMISSNUM(ScatterIndex)
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
i = 1
Do While i <= ActiveChart.SeriesCollection.Count
ActiveChart.FullSeriesCollection(i).Delete
Loop
' ActiveChart.SetSourceData Source:=Range("taboutput_withplots!$A:$A")
ActiveChart.SeriesCollection.NewSeries
Application.Worksheets("taboutput_withplots").Select
ActiveChart.FullSeriesCollection(ScatterIndex).Name = "=taboutput_withplots!" _
+ Range(Cells(2 + RowIndex * (ScatterIndex - 1), 1), Cells(2 + RowIndex * (InitialStartingIndex - 1), 1)).Address
ActiveChart.FullSeriesCollection(ScatterIndex).XValues = _
"=taboutput_withplots!" + Range(Cells(2 + RowIndex * (InitialStartingIndex - 1), 2), Cells(1 + RowIndex, 2)).Address
ActiveChart.FullSeriesCollection(ScatterIndex).Values = "=taboutput_withplots!" _
+ Range(Cells(2 + RowIndex * (ScatterIndex - 1), 13), Cells(1 + RowIndex, 13)).Address
'***************************************************************************************************'***************************************** Area of Interest **************************************** '***************************************************************************************************
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = "Time vs Theta"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Time vs Theta"
With Selection.Format.TextFrame2.TextRange.Characters(1, 13).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(5, 9).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlCategory).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Time, s"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Time, s"
With Selection.Format.TextFrame2.TextRange.Characters(1, 7).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 7).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlValue).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Theta, deg"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Theta, deg"
With Selection.Format.TextFrame2.TextRange.Characters(1, 10).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 6).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(7, 4).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
Instead of getting the expected result, I get the Error '424' Object Required in return at
ActiveChart.Axes(xlValue).AxisTitle.Select, and I found out it works when I use
xlCategoryinstead of
xlvalue, but it doesn't work for the y-axis. I tried changing
xlprimaryto
xlsecondaryin
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text` for the y-axis, but it spits out run-time error '-214767258(800004005)': Method 'Axes' of object'_Chart' failed.