VBA Error with Macro Recorder Setting Chart Axis Titles

BiochemBoi95

New Member
Joined
Jan 22, 2020
Messages
20
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Web
I am getting an error trying to set the titles for the x and y axis of a chart using a macro made by the macro recorder. I am getting a run time error 91 on line 59 which I have highligted red. Any help is greatly appreciated.

Rich (BB code):
Sub GraphMaker()
'
' GraphMaker Macro
'
' Keyboard Shortcut: Ctrl+Shift+G
'
    ActiveWindow.SmallScroll Down:=12
    ActiveCell.Offset(32, 6).Range("A1").Select
    ActiveCell.FormulaR1C1 = "0"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "5"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "6"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "7"
    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveWindow.SmallScroll Down:=-15
    ActiveCell.Offset(-40, -6).Range("A1").Select
    Selection.Copy
    ActiveWindow.SmallScroll Down:=24
    ActiveCell.Offset(35, 7).Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-21
    ActiveCell.Offset(-31, -7).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveWindow.SmallScroll Down:=21
    ActiveCell.Offset(32, 7).Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-15
    ActiveCell.Offset(-33, -7).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveWindow.SmallScroll Down:=15
    ActiveCell.Offset(34, 7).Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-18
    ActiveCell.Offset(-35, -7).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveWindow.SmallScroll Down:=21
    ActiveCell.Offset(36, 7).Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-18
    ActiveCell.Offset(-37, -7).Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    ActiveWindow.SmallScroll Down:=21
    ActiveCell.Offset(38, 7).Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.SmallScroll Down:=-6
    ActiveCell.Offset(-3, -1).Range("A1:B4").Select
    ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmooth).Select
    ActiveChart.SetSourceData Source:=Range("Test!$K$561:$L$564")
    ActiveSheet.Shapes("Chart 14").IncrementLeft 152.25
    ActiveSheet.Shapes("Chart 14").IncrementTop 155.25
    ActiveWindow.SmallScroll Down:=12
    ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
    ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Round Number"
    Selection.Format.TextFrame2.TextRange.Characters.Text = "Round Number"
    With Selection.Format.TextFrame2.TextRange.Characters(1, 12).ParagraphFormat
        .TextDirection = msoTextDirectionLeftToRight
        .Alignment = msoAlignCenter
    End With
    With Selection.Format.TextFrame2.TextRange.Characters(1, 12).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.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
    ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Nucleotide A %"
    Selection.Format.TextFrame2.TextRange.Characters.Text = "Nucleotide A %"
    With Selection.Format.TextFrame2.TextRange.Characters(1, 14).ParagraphFormat
        .TextDirection = msoTextDirectionLeftToRight
        .Alignment = msoAlignCenter
    End With
    With Selection.Format.TextFrame2.TextRange.Characters(1, 10).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(11, 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
End Sub
 
Last edited by a moderator:

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Watch MrExcel Video

Forum statistics

Threads
1,122,364
Messages
5,595,714
Members
414,013
Latest member
tnobbs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top