I sorted it out
Below code is how I did it.
Dim chr, sht, data As String
data = ActiveChart.name
sht = ActiveSheet.name
chr = Trim(Replace(data, sht, ""))
I captured the name in chr variable & replaced it with the name of the chart in the static part of the code.
The static part of the code now looks like this.
ActiveSheet.Shapes(chr).IncrementLeft -88.5
ActiveSheet.Shapes(chr).IncrementTop 125.25
ActiveSheet.Shapes(chr).ScaleWidth 1.58, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(chr).ScaleHeight 1.25, msoFalse, msoScaleFromTopLeft
And
Sheets("Associates").DrawingObjects(chr).RoundedCorners = True
Sheets("Associates").DrawingObjects(chr).Shadow = False
Even though I am marking this thread as solved, If anyone know a better approach, please let me know.
My Whole Code now looks like this.
Sub OverallErrorPareto()
Dim rng As Range
Dim LastRow As Long
With ActiveSheet
LastRow = .Range("C2:D2").End(xlDown).Row
Set rng = Union(.Range("C2:D2").Resize(LastRow - 1), .Range("F2:F2").Resize(LastRow - 1))
End With
Charts.Add
With ActiveChart
.ApplyCustomType ChartType:=XlChartType.xlColumnClustered
.SetSourceData Source:=rng, PlotBy:=xlColumns
With .SeriesCollection(2)
.ChartType = xlLineMarkers
.AxisGroup = 2
End With
.HasTitle = True
.ChartTitle.Characters.Text = "Error"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "CS"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Error#"
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Cum%"
.Location Where:=xlLocationAsObject, name:="Associates"
End With
Dim chr, sht, data As String
data = ActiveChart.name
sht = ActiveSheet.name
chr = Trim(Replace(data, sht, ""))
ActiveSheet.Shapes(chr).IncrementLeft -88.5
ActiveSheet.Shapes(chr).IncrementTop 125.25
ActiveSheet.Shapes(chr).ScaleWidth 1.58, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(chr).ScaleHeight 1.25, msoFalse, msoScaleFromTopLeft
With Selection.Border
.Weight = 2
.LineStyle = -1
End With
Sheets("Associates").DrawingObjects(chr).RoundedCorners = True
Sheets("Associates").DrawingObjects(chr).Shadow = False
Selection.Fill.TwoColorGradient Style:=msoGradientDiagonalDown, Variant:=1
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 40
.Fill.BackColor.SchemeColor = 36
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 0
.MaximumScale = 80
.MinorUnit = 2
.MajorUnit = 10
.Crosses = xlCustom
.CrossesAt = 0
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
Selection.Delete
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
Selection.Shadow = False
Selection.InvertIfNegative = False
Selection.Fill.TwoColorGradient Style:=msoGradientFromCorner, Variant:=1
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 17
.Fill.BackColor.SchemeColor = 2
End With
ActiveChart.SeriesCollection(2).Select
With Selection.Border
.ColorIndex = 6
.Weight = xlThin
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = 4
.MarkerForegroundColorIndex = 4
.MarkerStyle = xlCircle
.Smooth = False
.MarkerSize = 5
.Shadow = False
End With
ActiveChart.PlotArea.Select
End Sub
Its also working smoothly.
Thanks Xld, Andy and Mdmackillop for all your time, help & guidance.
Sudhir