G
Guest
I recently had this question answered very comprehensively. However, I've
been told that I need to show my data on a chart in % form. Can anyone help
modify the following macro to automatically generate charts where the source
data is on a row by row basis with four columns showing data (don't need to
show targets on this one). I've tried to modify it myself, but can't seem to
get it working. The columns are all next to each other - no gaps. To clarigy,
I need Name, %Score1, %Score2, %Score3 & %Score 4. That's it.
Regards,
JDB
Jon Peltier In: microsoft.public.excel.charting
Select your range (including header row) and run this macro:
Sub MakeMyCharts()
'
Dim ws As Worksheet
Dim rng As Range
Dim Yaddr As String
Dim Y2addr As String
Dim Xaddr As String
Dim iRow As Long
Dim iSrs As Long
Dim iAddr As Long
Dim cht As Chart
Set ws = ActiveSheet
If TypeName(Selection) <> "Range" Then
MsgBox "Select the data range for the charts"
Exit Sub
End If
Set rng = Selection
For iRow = 2 To rng.Rows.Count
Set cht = Charts.Add
cht.Name = rng.Cells(iRow, 1).Value & " - " & rng.Cells(iRow, 2).Value
For iSrs = cht.SeriesCollection.Count To 1 Step -1
cht.SeriesCollection(iSrs).Delete
Next
With cht.SeriesCollection.NewSeries
.Name = rng.Rows(iRow).Resize(1, 2)
Yaddr = "=("
Y2addr = "=("
Xaddr = "=("
For iAddr = 3 To 9 Step 2
Yaddr = Yaddr & "'" & ws.Name & "'!" & rng.Cells(iRow,
iAddr).Address(ReferenceStyle:=xlR1C1) & ","
Y2addr = Y2addr & "'" & ws.Name & "'!" & rng.Cells(iRow, iAddr +
1).Address(ReferenceStyle:=xlR1C1) & ","
Xaddr = Xaddr & "'" & ws.Name & "'!" & rng.Cells(1,
iAddr).Address(ReferenceStyle:=xlR1C1) & ","
Next
Yaddr = Left$(Yaddr, Len(Yaddr) - 1) & ")"
Y2addr = Left$(Y2addr, Len(Y2addr) - 1) & ")"
Xaddr = Left$(Xaddr, Len(Xaddr) - 1) & ")"
.Values = Yaddr
.XValues = Xaddr
.ChartType = xlLineMarkers
End With
With cht.SeriesCollection.NewSeries
.Name = "Target"
.Values = Y2addr
.ChartType = xlColumnClustered
End With
Next
End Sub
- Jon
been told that I need to show my data on a chart in % form. Can anyone help
modify the following macro to automatically generate charts where the source
data is on a row by row basis with four columns showing data (don't need to
show targets on this one). I've tried to modify it myself, but can't seem to
get it working. The columns are all next to each other - no gaps. To clarigy,
I need Name, %Score1, %Score2, %Score3 & %Score 4. That's it.
Regards,
JDB
Jon Peltier In: microsoft.public.excel.charting
Select your range (including header row) and run this macro:
Sub MakeMyCharts()
'
Dim ws As Worksheet
Dim rng As Range
Dim Yaddr As String
Dim Y2addr As String
Dim Xaddr As String
Dim iRow As Long
Dim iSrs As Long
Dim iAddr As Long
Dim cht As Chart
Set ws = ActiveSheet
If TypeName(Selection) <> "Range" Then
MsgBox "Select the data range for the charts"
Exit Sub
End If
Set rng = Selection
For iRow = 2 To rng.Rows.Count
Set cht = Charts.Add
cht.Name = rng.Cells(iRow, 1).Value & " - " & rng.Cells(iRow, 2).Value
For iSrs = cht.SeriesCollection.Count To 1 Step -1
cht.SeriesCollection(iSrs).Delete
Next
With cht.SeriesCollection.NewSeries
.Name = rng.Rows(iRow).Resize(1, 2)
Yaddr = "=("
Y2addr = "=("
Xaddr = "=("
For iAddr = 3 To 9 Step 2
Yaddr = Yaddr & "'" & ws.Name & "'!" & rng.Cells(iRow,
iAddr).Address(ReferenceStyle:=xlR1C1) & ","
Y2addr = Y2addr & "'" & ws.Name & "'!" & rng.Cells(iRow, iAddr +
1).Address(ReferenceStyle:=xlR1C1) & ","
Xaddr = Xaddr & "'" & ws.Name & "'!" & rng.Cells(1,
iAddr).Address(ReferenceStyle:=xlR1C1) & ","
Next
Yaddr = Left$(Yaddr, Len(Yaddr) - 1) & ")"
Y2addr = Left$(Y2addr, Len(Y2addr) - 1) & ")"
Xaddr = Left$(Xaddr, Len(Xaddr) - 1) & ")"
.Values = Yaddr
.XValues = Xaddr
.ChartType = xlLineMarkers
End With
With cht.SeriesCollection.NewSeries
.Name = "Target"
.Values = Y2addr
.ChartType = xlColumnClustered
End With
Next
End Sub
- Jon