Hi,
This below code is not working in 2007, but its working in 2003 fine. May I know can we do any betterment to the code. Which can run in any Office.
Sub chrt_col()
Dim ws As Worksheet
Dim chrtrng As Range
Dim myChart As Chart
Dim rng As Range
ThisWorkbook.Worksheets("Analysis").Select
ThisWorkbook.Worksheets("Analysis").Range("B4").CurrentRegion.Select
Set rng = Selection
cl = rng.Columns.Count - 1
rw = rng.Rows.Count + 1
chtrng1 = "B4" & ":" & "F" & rw
Set chrtrng = ThisWorkbook.Worksheets("Analysis").Range(chtrng1)
Set myChart = Charts.Add
Set myChart = myChart.Location(xlLocationAsObject, "Analysis")
With myChart
.SetSourceData chrtrng, xlColumns
.HasTitle = True
.ChartTitle.Caption = "Change"
.ChartType = xlColumnClustered
End With
With ActiveChart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "Sts"
.HasMajorGridlines = False
.HasMinorGridlines = False
'.MajorTickMark = xlTickMarkNone
End With
With ActiveChart.Axes(xlCategory).AxisTitle
.Text = "Sts"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = xlHorizontal
End With
With ActiveChart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Caption = "Vol"
.HasMajorGridlines = False
.HasMinorGridlines = False
.MinimumScale = 0
'.MaximumScale = 10
.MaximumScaleIsAuto = True
.MajorUnit = 2
.MinorUnit = 0.4
End With
With ActiveChart.Axes(xlValue).AxisTitle
.Text = "Vol"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = xlUpward
End With
With ActiveChart.ChartTitle
.Text = "Change"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = xlHorizontal
End With
With ActiveChart.PlotArea
.Interior.ColorIndex = xlNone
.Border.LineStyle = xlNone
.Top = 20
.Height = 161
.Width = 325
End With
With ActiveChart
.HasDataTable = True
.HasLegend = False
End With
With ActiveChart.DataTable
.ShowLegendKey = True
End With
With ActiveChart.SeriesCollection(1)
.Border.LineStyle = xlAutomatic
.Interior.ColorIndex = 39
End With
With ActiveChart.SeriesCollection(2)
.Border.LineStyle = xlAutomatic
.Interior.ColorIndex = 4
End With
With ActiveChart.SeriesCollection(3)
.Border.LineStyle = xlAutomatic
.Interior.ColorIndex = 26
End With
With ActiveChart.SeriesCollection(4)
.Border.LineStyle = xlAutomatic
.Interior.ColorIndex = 27
End With
With ActiveChart.ChartArea
.Font.Name = "Arial"
.Font.Size = 8
.Font.FontStyle = "Bold"
End With
With ActiveChart.Parent
.Left = 525
.Width = 350
.Top = 25
.Height = 200
End With
Set myChart = Nothing
Set chrtrng = Nothing
End Sub