what's wrong with this macro, keep getting the same error - vba

I have been trying to make a macro to automate the creation of a graph form one of the output for a machine. I have written the steps down and practiced them many times buy keep getting an error and don't know what it means or how to fix it. I have # the line that my errors appears. I think the rest of the code is good. I used the macro recorder to create this.
here is the code:
Macro4 Macro
'
'
Range("I2").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$W$1086").AutoFilter Field:=9, Criteria1:="<700000"
Range("G99:I165").Select
Selection.ClearContents
Range("G1:L1083").Select
ExecuteExcel4Macro "(FALSE,227,4)"
ActiveChart.SetSourceData Source:=Range("'Raw Data'!$G$1:$L$1083")
ActiveSheet.Shapes("Chart 1").IncrementLeft -482
ActiveSheet.Shapes("Chart 1").IncrementTop 113
ActiveSheet.Shapes("Chart 1").ScaleWidth 3.2611111111, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.1782407407, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.0340715503, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 2.6895874263, msoFalse, _
msoScaleFromTopLeft
ActiveChart.Axes("xlCategory").Select
this line below is my problem
Selection.Border.Color = RGB(, , )
Selection.TickLabelPosition = xlLow
ActiveChart.Axes(xlCategory).TickLabelSpacing = 1
ActiveChart.Axes(xlCategory).TickLabelSpacing = 100
ActiveChart.Axes("xlValue").Select
With ActiveChart.Axes(xlValue)
.MinimumScale = -90
.Crosses = xlCustom
End With
With ActiveChart.Axes(xlValue)
.MaximumScale = 30
.Crosses = xlCustom
End With
ActiveChart.SeriesCollection(6).Select
ActiveChart.SeriesCollection(3).Select
ActiveChart.SeriesCollection(3).AxisGroup = 2
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(3).Select
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).AxisGroup = 2
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Select
ActiveWindow.ScrollColumn = 9
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 1
Range("A1047").Select
Selection.Copy
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartTitle.Select
ActiveChart.Paste
ActiveChart.ChartTitle.Text = "017306T11FluCandida "
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"017306T11FluCandida "
With Selection.Format.TextFrame2.TextRange.Characters(1, 31).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignLeft
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 30).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(31, 1).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
Range("A1086").Select

You are trying to call ExecuteExcel4Macro "(FALSE,227,4)" - the argument for this Method should be in the format Function(argument1, argument2, ..),depending on the macro function you are trying to call. However, you seem to have omitted the Function name itself.
Essentially, you are telling the computer "do something with these values", but not giving it any suggestion as to what to do. So, it (quite naturally) objects, and throws an error.
More info on the Application.ExecuteExcel4Macro Method is available on MSDN: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-executeexcel4macro-method-excel (Just hit F1 in VBA when you have your typing-cursor on the function you want to look up)

Related

VBA creating two same pie charts ona different worksheet of a same same workbook

I want to create a pie chart for a pivot table.My pivot table is located at the same workbook in worksheet "New_Pivot".I want to create pie chart in the same workbook but different worksheet named "Pie_chart".I have created a code given below with formatting the size and background colour.My code is given below:
Sub Formattedchart()
'
' Formattedchart Macro
'
'
Sheets("New_pivot").Select
Range("A1:B16").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlPie
ActiveChart.ShowValueFieldButtons = False
Dim cht1 As Shape
Set cht1 = ActiveSheet.Shapes(1)
cht1.Name = "chart001"
ActiveSheet.ChartObjects("chart001").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels
ActiveSheet.ChartObjects("chart001").Activate
ActiveSheet.Shapes("chart001").IncrementLeft -18
ActiveSheet.Shapes("chart001").IncrementTop -125.25
ActiveSheet.ChartObjects("chart001").Activate
ActiveSheet.Shapes("chart001").ScaleWidth 0.9375, msoFalse, msoScaleFromTopLeft
ActiveSheet.ChartObjects("chart001").Activate
ActiveSheet.Shapes("chart001").ScaleHeight 1.73090296, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("chart001").Activate
ActiveSheet.Shapes("chart001").ScaleHeight 1.1644936737, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("chart001").Activate
ActiveSheet.Shapes("chart001").ScaleWidth 1.1377777778, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("chart001").Activate
With ActiveSheet.Shapes("chart001").ThreeD
.BevelTopType = msoBevelCircle
.BevelTopInset = 6
.BevelTopDepth = 6
End With
ActiveSheet.ChartObjects("chart001").Activate
With ActiveSheet.Shapes("chart001").Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent6
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0.6000000238
.Solid
End With
With ActiveSheet.Shapes("chart001").Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent6
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0.6000000238
.Transparency = 0
.Solid
End With
ActiveSheet.ChartObjects("chart001").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ChartType = xl3DPie
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).ApplyDataLabels
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Consolidated"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Consolidated"
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 = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveSheet.ChartObjects("chart001").Activate
ActiveChart.ChartTitle.Select
Selection.Caption = "=New_pivot!R1C2"
End Sub
Unfortunately I am not be able to create the same chart in worksheet "Pie_chart" and also I need to create two same pie charts on this worksheet"Pie-Chart". I am new here so I am unable to perform this operation where I want to create two same pie charts on "Pie_chart" worksheet.

How to plot graphs on their corresponding sheet?

I am taking data from multiple spreadsheets and plotting them on a chart, for each of the respective spreadsheets. I want the data from Spreadsheet1 to plot a graph also on Spreadsheet1. Currently, my code plots all of the graphs on the last sheet, so the graphs for sheets 1,2,3, etc are all plotted on the last sheet. I am unsure how to fix this as I am new to VBA. I recorded a macro to get the code to plot the data.
here is my plotting code:
For j = 1 To size
'creates chart
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveSheet.Shapes("Chart 1").IncrementLeft 696.75
ActiveSheet.Shapes("Chart 1").IncrementTop -81.75
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.3333333333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.6909722222, msoFalse, _
msoScaleFromTopLeft
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Length and Depth Data"""
ActiveChart.FullSeriesCollection(1).XValues = Worksheets("Case " & overview(j, 1)).Range("$R$10:$R$6000")
ActiveChart.FullSeriesCollection(1).Values = Worksheets("Case " & overview(j, 1)).Range("$S$10:$S$6000")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""B31G MAOP"""
ActiveChart.FullSeriesCollection(2).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(2).Values = Worksheets("Case " & overview(j, 1)).Range("$I$10:$I$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""B31G 1.25SF"""
ActiveChart.FullSeriesCollection(3).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(3).Values = Worksheets("Case " & overview(j, 1)).Range("$J$10:$J$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""B31G 1.39SF"""
ActiveChart.FullSeriesCollection(4).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(4).Values = Worksheets("Case " & overview(j, 1)).Range("$P$10:$P$159")
ActiveWindow.SmallScroll Down:=-126
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
ActiveWindow.SmallScroll Down:=6
Range("W32").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveSheet.Shapes("Chart 2").IncrementLeft 311.25
ActiveSheet.Shapes("Chart 2").IncrementTop 213
ActiveWindow.SmallScroll Down:=18
Range("AD46:AD47").Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.Shapes("Chart 2").ScaleWidth 1.3145833333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 2").ScaleHeight 1.4930555556, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("Chart 2").Activate
Application.CutCopyMode = False
Application.CutCopyMode = False
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Length and Depth Data"""
ActiveChart.FullSeriesCollection(1).XValues = Worksheets("Case " & overview(j, 1)).Range("$R$10:$R$6000")
ActiveChart.FullSeriesCollection(1).Values = Worksheets("Case " & overview(j, 1)).Range("$S$10:$S$6000")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""MB31G MAOP"""
ActiveChart.FullSeriesCollection(2).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(2).Values = Worksheets("Case " & overview(j, 1)).Range("$N$10:$N$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""MB31G 1.25SF"""
ActiveChart.FullSeriesCollection(3).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(3).Values = Worksheets("Case " & overview(j, 1)).Range("$O$10:$O$159")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""B31G 1.39SF"""
ActiveChart.FullSeriesCollection(4).XValues = Worksheets("Case " & overview(j, 1)).Range("$C$10:$C$159")
ActiveChart.FullSeriesCollection(4).Values = Worksheets("Case " & overview(j, 1)).Range("$P$10:$P$159")
ActiveWindow.SmallScroll Down:=-117
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveWindow.SmallScroll Down:=9
ActiveChart.ChartTitle.Text = "B31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "B31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).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
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveWindow.SmallScroll Down:=-12
ActiveChart.ChartTitle.Text = "B31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "B31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).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, 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 = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartTitle.Select
Application.CommandBars("Format Object").Visible = False
ActiveChart.ChartTitle.Text = "MB31G Burst Curve"
Selection.Format.TextFrame2.TextRange.Characters.Text = "MB31G Burst Curve"
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).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
Next j
I would do this in a completely different way. But a quick fix to the wall of code that you provided would be adding this to the beginning just right after your for loop starts:
For j = 1 To size
'creates chart
Worksheets("Case " & overview(j, 1)).Activate
'Rest of the code would be the same
'...
Next j
You should read this question and its answers:
How to avoid selecting and activating in VBA?
You apply all instructions on the ActiveSheet. You can select specific sheets by Sheets(1).Activate or Sheets("sheet_name").Activate.
You can also iterate over all sheets by
For Each sht In ActiveWorkbook.Sheets
If sht.Name Like "..." Then ...
Next sht

Excel: Dynamically Update Chart Series in for loop

I have created a macro which will be used to create an individual chart for each of the over 2000 items who's data is stored in another Excel workbook. The macro goes through a for loop, creating a new chart, setting the chart series using the data from the other Excel workbook and then doing all of the formatting work after that. I am however still having a problem trying to dynamically update the series range after each for loop. A sample of the series is found below:
for i = 1 to Row.Count
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$2:$BA$2"
I was wondering how I would be able to modify the above static range, and make it dynamic so that the second chart uses data from row 3, the third chart uses data from row 4 and so on through the entire range.
Entire Code For Reference:
Sub Macro4()
Dim ws, ws2 As Worksheet
Dim graphName As String
Dim i As Integer
Dim srange As Range
Dim grp As Chart
Dim lw As Long
Set ws = Sheets("Interactive Data")
Set ws2 = Sheets("Graphs")
For i = 1 To 3 'Row.Count
ws2.Shapes.AddChart2(227, xlLine).Select
With ActiveChart
.Parent.Name = ws.Cells(i + 1, 1)
End With
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Annual Inv."""
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1 '*****ADJUST THIS
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""Status Quo"""
ActiveChart.FullSeriesCollection(2).Values = _
"='[Simplified Interactive - V2.xlsm]No Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1 '*****ADJUST THIS
ActiveChart.FullSeriesCollection(2).XValues = "=Graphs!$A$1:$AW$1"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).ReversePlotOrder = True
ActiveChart.Axes(xlValue).Crosses = xlMaximum
ActiveChart.ChartArea.Select
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).TickLabels.Font.Color = RGB(0, 0, 0)
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).TickLabels.Font.Color = RGB(0, 0, 0)
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.SetElement (msoElementLegendRight)
ActiveChart.Legend.Select
ActiveChart.Legend.Select
Selection.Position = xlBottom
ActiveChart.Legend.LegendEntries(2).Select
ActiveChart.Legend.LegendEntries(1).Select
ActiveChart.Legend.Select
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.ChartTitle.Select
Selection.Characters.Text = "Degradation"
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
ActiveChart.Axes(xlCategory).AxisTitle.Select
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Year"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Year"
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.SetElement msoElementPrimaryValueAxisTitleBelowAxis
ActiveChart.Axes(xlValue).AxisTitle.Select
With Selection.Format.TextFrame2.TextRange.Characters(1, 10).Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Condition"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Condition"
With Selection.Format.TextFrame2.TextRange.Characters(1, 30).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 8).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.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(9, 22).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.FullSeriesCollection(1).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
End With
ActiveChart.FullSeriesCollection(2).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
End With
ActiveChart.ChartArea.Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 53.6250393701, _
113.1250393701, 76.5, 15.75).Select
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"Status Quo"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 28).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 28).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
Selection.ShapeRange.ScaleWidth 1.568627451, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.0476190476, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.IncrementLeft -6
Selection.ShapeRange.IncrementTop 6
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
.Solid
End With
ActiveChart.PlotArea.Select
ActiveChart.Shapes.Range(Array("TextBox 1")).Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 58.8750393701, _
42.3750393701, 67.5, 12.75).Select
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 67.8750393701, _
45.6250393701, 104.25, 11.25).Select
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = _
"Optimal"
Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 17).ParagraphFormat. _
FirstLineIndent = 0
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 7).Font
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(8, 10).Font
.BaselineOffset = 0
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Size = 8
.Name = "+mn-lt"
End With
Selection.ShapeRange.ScaleHeight 1.4666666667, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleWidth 0.7553956835, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 1.0454545455, msoFalse, _
msoScaleFromBottomRight
Selection.ShapeRange.IncrementLeft -22.5
Selection.ShapeRange.IncrementTop 12.75
Range("R16").Select
Next i
End Sub
I was wondering how I would be able to modify the above static range, and make it dynamic so that the second chart uses data from row 3, the third chart uses data from row 4 and so on through the entire range.
By using a variable?
rw = 2
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & rw & ":$BA$" & rw
And if you want it "connected" to your For Loop i.e instead of using rw variable, you want to use i then
ActiveChart.FullSeriesCollection(1).Values = _
"='[Simplified Interactive - V2.xlsm]Maint. FDC'!$D$" & i & ":$BA$" & i
EDIT
the graph only plots the points for the first chart, but doesn't plot the series for charts 2 and beyond. The data does exist, so Any idea why it would be doing that? – Xcelrate
The code plots for all the 3 graphs for me. BTW, avoid the use of Activechart. Work with Objects. Here is a very basic example of how your code will look like.
Sub Sample()
Dim ws As Worksheet
Dim objChrt As ChartObject
Dim myChart As Chart
Dim chartTop As Long
Set ws = Sheets("Graphs")
'~~> This will define the "Left" of the chart
chartleft = 10
For i = 1 To 3
Set objChrt = ws.ChartObjects.Add(chartleft, 10, 200, 200)
Set myChart = objChrt.Chart
With myChart
.SeriesCollection.NewSeries
.FullSeriesCollection(1).Name = "Test"
.FullSeriesCollection(1).Values = "='Maint. FDC'!$D$" & i + 1 & ":$BA$" & i + 1
End With
chartleft = chartleft + 220
Next i
End Sub
Worksheet Maint. FDC
Worksheet Graphs
Interesting Read
ChartObjects.Add Method

How can I select a file in a dropdownbox which will then be opened by excel?

I already created the dropdownbox and it points to a certain directory which contains the .csv files. I can see the files in the dropdownbox, but I want to open them as soon as I click on them. How can I accomplish this in the Visual Basic editor? Here is my code of the dropdownbox.
P.S. I just started programming in Visual Basic.
Option Explicit
Private Sub DropdownFiles()
Dim name
For Each name In ListDirectory(Path:="C:\Users\Test\Desktop\Macro's\", AttrInclude:=vbNormal, AttrExclude:=vbSystem Or vbHidden)
Me.ComboBox1.AddItem name
Next name
End Sub
Function ListDirectory(Path As String, AttrInclude As VbFileAttribute, Optional AttrExclude As VbFileAttribute = False) As Collection
Dim Filename As String
Dim Attribs As VbFileAttribute
Set ListDirectory = New Collection
Filename = Dir(Path, AttrInclude)
While Filename <> ""
Attribs = GetAttr(Path & Filename)
' If Attribs And AttrInclude And Not (Attribs And AttrExclude) Then
If Not (Attribs And AttrExclude) Then
ListDirectory.Add Filename, Path & Filename
End If
Filename = Dir
Wend
End Function
Private Sub OpenButton()
End Sub
The macro which I run. It's located in a directory near the .csv files
Private Sub Macro()
'
' Macro
'
'
Dim docpath As String
docpath = "TEXT;" & ThisWorkbook.Path & "\Test.csv"
'With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\Users\Test\Desktop\Macro's\Test.csv", Destination:=Range("$A$1"))
With ActiveSheet.QueryTables.Add(Connection:=docpath, Destination:=Range("$A$1"))
' docpath, Destination:=Range("$A$1"))
' .CommandType = 0
.name = "calllog"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(4, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
ActiveSheet.name = "Sheet1"
End With
Range("A1:I9999").Select
Selection.Columns.AutoFit
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Range("I2:I829").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("I2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("I2:I9999")
.Header = xlNo
.MatchCase = True
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("T1").Select
ActiveCell.FormulaR1C1 = "60"
Range("T1").Select
Selection.Copy
Range("F2:F829").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlDivide, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "0.00"
Range("G2:G829").Select
Range("T1").Select
Selection.Copy
Range("G2:G829").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlDivide, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "0.00"
Range("T1").Select
Selection.ClearContents
Range("A437:I829").Select
Selection.Cut Destination:=Range("A439:I831")
Range("A439:I831").Select
Range("A439:I506").Select
Range("I506").Activate
Selection.Cut Destination:=Range("A438:I505")
Range("L452").Select
Range("A2:A436,F2:F436").Select
Range("F436").Activate
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range( _
"Sheet1!$A$2:$A$436,Sheet1!$F$2:$F$436")
ActiveSheet.Shapes("Chart 1").IncrementLeft 304.5
ActiveSheet.Shapes("Chart 1").IncrementTop -139.5
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Aantal gebelde minuten (Inbound)"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Aantal gebelde minuten (Inbound)"
With Selection.Format.TextFrame2.TextRange.Characters(1, 32).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).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(15, 18).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
Range("O27").Select
Range("A438:A505,F438:F505").Select
Range("F505").Activate
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range( _
"Sheet1!$A$438:$A$505,Sheet1!$F$438:$F$505")
ActiveSheet.Shapes("Chart 2").IncrementLeft 312.75
ActiveSheet.Shapes("Chart 2").IncrementTop -61.5
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Aantal gebelde minuten (Internal)"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Aantal gebelde minuten (Internal)"
With Selection.Format.TextFrame2.TextRange.Characters(1, 33).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 33).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
Range("M458").Select
Application.CommandBars("Format Object").Visible = False
Range("A507:A831,F507:F831").Select
Range("F831").Activate
ActiveSheet.Shapes.AddChart2(216, xlBarClustered).Select
ActiveChart.SetSourceData Source:=Range( _
"Sheet1!$A$507:$A$831,Sheet1!$F$507:$F$831")
ActiveSheet.Shapes("Chart 3").IncrementLeft 301.5
ActiveSheet.Shapes("Chart 3").IncrementTop -73.5
ActiveChart.ChartTitle.Select
Application.CommandBars("Format Object").Visible = False
ActiveChart.ChartTitle.Text = "Aantal gebelde minuten (Outbound)"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Aantal gebelde minuten (Outbound)"
With Selection.Format.TextFrame2.TextRange.Characters(1, 33).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 33).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
Range("P535").Select
ActiveWindow.SmallScroll Down:=-18
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Parent.Cut
Sheets("Sheet1").Select
Sheets("Sheet1").name = "Log"
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Sheets("Sheet1").name = "Chart"
Range("A1").Select
ActiveSheet.Paste
Sheets("Log").Select
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.Parent.Cut
Sheets("Chart").Select
Range("J1").Select
ActiveSheet.Paste
Sheets("Log").Select
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.Parent.Cut
Sheets("Chart").Select
Range("E19").Select
ActiveSheet.Paste
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.Shapes("Chart 1").ScaleWidth 1.1479166667, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 1.1770833333, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.Shapes("Chart 2").ScaleWidth 1.1416666667, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 2").ScaleHeight 1.1736111111, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveSheet.Shapes("Chart 3").ScaleWidth 1.1979166667, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 3").ScaleHeight 1.2361111111, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.PlotArea.Select
Selection.Left = 85.964
Selection.Top = 37.09
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 3").IncrementLeft 36
ActiveSheet.Shapes("Chart 3").IncrementTop -0.75
Sheets("Log").Select
End Sub
Right-click the dropdown box on the form and select "View Code". In the right top corner of the screen select "Change" event and use the code below:
Private Sub ComboBox1_Change()
Dim WbSource As Workbook
Dim pth As String
Dim fnme As String
fnme = ComboBox1.Value
pth = "C:\Users\Test\Desktop\Macro's\"
Application.Run "CustomMacro", pth & fnme
End Sub
If the answer works, please mark as accepted.
I understand that you need to run a macro on the opened workbook now. This can be done in a few ways, here is my suggestion to solve the problem:
1) Try to stay away from ThisWorkbook and ActiveWorksheet - use variables that are dimensioned as workbooks and worksheets
2) You can pass variables to the macro in several ways - you can make a variable global (I suggest you read up on different levels of variables), but the easiest way is to make the variable an argument for the function.
3) For my solution, I will assume you have two workbooks each with one sheet. I will call them target and source: source is the workbook selected from dropdown menu, and the target is the one where the macro is located. The dropdown box will remember the path to the source and will pass it on to the other macro.
Sub CustomMacro(SrceWBPath as String)
Dim WbSource as workbook
Dim WbTarget as workbook
Dim WrkShtSrc as Worksheet
Dim WrkShtTrgt as Worksheet
Set WbTarget = This.Workbook
Set WbSource = Workbooks.Open (SrceWbPath)
Set WrkShtSrc = wbSource.Worksheets("insert_name_of_the_source_worksheet_here")
Set WrkShtTrgt = wbTarget.Worksheets("insert_name_of_the_target_worksheet_here")
'Then insert the rest of your code here, calling the proper sheets as required. Also, move away from `.Select` command - it just consumes a lot of processing time. Define variable such as `Range` and perform operations on them.
End Sub

Make macro independent, to be used for generating a graph in multiple sheets in excel

I am rookie when it comes to VBA but essentially I want to create a macro that I can then use to run in multiple sheets. I have a lot of data.
What I have done so far is used the macro recording capability in excel to make the graph and then saving it. This works fine and my graph is generated every time its run on the same sheet. However, when I try to run it in a different sheet, it just generates a graph from the previous sheet. I have looked online and tried to edit the source name to ActiveSheet! but it hasn't worked. Here is my code:
Min ret save
Sub minret_v1()
'
' minret_v1 Macro
'
ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""0"""
ActiveChart.FullSeriesCollection(1).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(1).Values = "='20160916 Acell 1'!$B$6:$B$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).Name = "=""50"""
ActiveChart.FullSeriesCollection(2).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(2).Values = _
"='20160916 Acell 1'!$D$953:$D$1033"
ActiveChart.FullSeriesCollection(2).Values = "='20160916 Acell 1'!$D$6:$D$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(3).Name = "=""100"""
ActiveChart.FullSeriesCollection(3).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(3).Values = "='20160916 Acell 1'!$F$6:$F$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(4).Name = "=""150"""
ActiveChart.FullSeriesCollection(4).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(4).Values = "='20160916 Acell 1'!$H$6:$H$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(5).Name = "=""200"""
ActiveChart.FullSeriesCollection(5).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(5).Values = "='20160916 Acell 1'!$J$6:$J$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(6).Name = "=""250"""
ActiveChart.FullSeriesCollection(6).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(6).Values = "='20160916 Acell 1'!$L$6:$L$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(7).Name = "=""300"""
ActiveChart.FullSeriesCollection(7).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(7).Values = "='20160916 Acell 1'!$N$6:$N$1033"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(8).Name = "=""350"""
ActiveChart.FullSeriesCollection(8).XValues = _
"='20160916 Acell 1'!$A$6:$A$1033"
ActiveChart.FullSeriesCollection(8).Values = "='20160916 Acell 1'!$P$6:$P$1033"
ActiveWindow.ScrollRow = 993
ActiveWindow.ScrollRow = 987
ActiveWindow.ScrollRow = 970
ActiveWindow.ScrollRow = 945
ActiveWindow.ScrollRow = 897
ActiveWindow.ScrollRow = 761
ActiveWindow.ScrollRow = 494
ActiveWindow.ScrollRow = 431
ActiveWindow.ScrollRow = 356
ActiveWindow.ScrollRow = 237
ActiveWindow.ScrollRow = 214
ActiveWindow.ScrollRow = 165
ActiveWindow.ScrollRow = 142
ActiveWindow.ScrollRow = 109
ActiveWindow.ScrollRow = 89
ActiveWindow.ScrollRow = 80
ActiveWindow.ScrollRow = 52
ActiveWindow.ScrollRow = 46
ActiveWindow.ScrollRow = 38
ActiveWindow.ScrollRow = 37
ActiveWindow.ScrollRow = 35
ActiveWindow.ScrollRow = 34
ActiveWindow.ScrollRow = 32
ActiveWindow.ScrollRow = 31
ActiveWindow.ScrollRow = 29
ActiveWindow.ScrollRow = 28
ActiveWindow.ScrollRow = 25
ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 1
ActiveChart.ApplyChartTemplate ( _
"C:\Users\Santiago\AppData\Roaming\Microsoft\Templates\Charts\Mult Lines_decay.crtx" _
)
ActiveChart.Axes(xlValue).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "gamma(nm)"
Selection.Format.TextFrame2.TextRange.Characters.Text = "gamma(nm)"
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 9).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.Axes(xlCategory).AxisTitle.Select
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = _
"Distance from interaction"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Distance from interaction"
With Selection.Format.TextFrame2.TextRange.Characters(1, 25).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 25).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 18
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Acell 20160916"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Acell 20160916"
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 14).Font
.BaselineOffset = 0
.Bold = msoTrue
.NameComplexScript = "Arial"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Fill.Transparency = 0
.Fill.Solid
.Size = 21.6
.Italic = msoFalse
.Kerning = 12
.Name = "Arial"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
Range("R10").Select
End Sub
If anyone can help me it would be much appreciated. Thank you for your time.
You can save the macro as an Add-in. It is then available when you start excel.
You can also distribute the Add-in.
Otherwise, you can add the macro to your personal book.
https://support.office.com/en-us/article/Copy-your-macros-to-a-Personal-Macro-Workbook-aa439b90-f836-4381-97f0-6e4c3f5ee566