Legend is not picking correctly

suresh ullanki

Board Regular
Joined
Apr 29, 2013
Messages
67
Hi,

The following VBA code creates charts. however, It is not picking up correct legend which should be Range("$J$1:$S$1") for all the charts. it is picking up as Seres1, series2 and etc... please help to correct the code




Sub test()
Dim Row As Integer
Dim ws As Worksheet
Dim rng As Range
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row - 1
Set ws = Sheets("Sheet1")
For Row = 1 To lastrow
Set rng = ws.Range("$J$1:$S$1").Offset(Row, 0)
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(ws.Name & "!" & rng.Address)
ActiveChart.ChartType = xlBarClustered
ActiveChart.PlotBy = xlColumns
ActiveChart.SetElement (msoElementLegendBottom)
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 222
ActiveChart.ChartTitle.Text = "WIP"
ActiveChart.SetElement (msoElementDataLabelOutSideEnd)
Next Row
Set ws = Nothing
Set rng = Nothing
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top