Hi all,
I've put together some code linked to a button in my data sheet ("Scores"). When pressed, this creates a bar chart in separate worksheets for each row of data. The code probably doesn't look too tidy, but it works fine
The data for the chart is in columns H to BZ, of these H is used for the graph title/worksheet name and all other columns are numbers 0-100
Now, I'd also like to add a target line onto these charts - this would be horizontal but at a different level for each graph so I can't just draw it in, the data for this is stored in column E. I wondered if anyone might be able to give any ideas on whether this is possible, or would it be a better move to create a separate target line graph over the top with a transparent background?
Sub Charts()
Dim Ws As Worksheet
Dim NewWs As Worksheet
Dim cht As Chart
Dim LastRow As Long
Dim CurrRow As Long
Set Ws = ThisWorkbook.Worksheets("Scores")
LastRow = Ws.Range("A65536").End(xlUp).Row
For CurrRow = 3 To LastRow
Set NewWs = ThisWorkbook.Worksheets.Add
NewWs.Name = Ws.Range("H" & CurrRow).Value
Set cht = ThisWorkbook.Charts.Add
With cht
.ChartType = xlColumnClustered
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = "=" & Ws.Name & "!R" & CurrRow & "C78:R" & CurrRow & "C9"
.SeriesCollection(1).Name = "=" & Ws.Name & "!R" & CurrRow & "C8"
.Location Where:=xlLocationAsObject, Name:=NewWs.Name
ActiveChart.SeriesCollection(1).XValues = "='Scores'!$I$2:$BZ$2"
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = 100
ActiveChart.Axes(xlValue).MajorUnit = 10
End With
Dim RngToCover As Range
Dim ChtOb As ChartObject
Set RngToCover = ActiveSheet.Range("A1:AC46")
Set ChtOb = ActiveChart.Parent
ChtOb.Height = RngToCover.Height
ChtOb.Width = RngToCover.Width
ChtOb.Top = RngToCover.Top
ChtOb.Left = RngToCover.Left
Next CurrRow
End Sub
Thanks, Adam
Bookmarks