Log in

View Full Version : [SOLVED:] ActiveChart Source PlotBy…With Scroll.



omnibuster
05-19-2010, 02:48 PM
Hi.

I was trying to make Chart with ScrollBar, but no sucsess??


Private Sub ScrollBar1_Change()
Dim Range1 As Range
Range("F2").Select 'ScrollBar.value
Set Range1 = Range("A2", ActiveCell.Value)
' Range1.Select
ActiveSheet.ChartObjects("ANA").Activate
ActiveChart.PlotArea.Select
' ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A2:D136"), PlotBy:=xlColumns
' .Application-defined or object-defined Error
ActiveChart.SetSourceData Source:=ActiveSheet.Range(Range1), PlotBy:=xlColumns
End Sub

p45cal
05-20-2010, 04:38 AM
try:

ActiveChart.SetSourceData Source:=Range1, PlotBy:=xlColumns
also consider changing

Set Range1 = Range("A2", ActiveCell.Value)
to

Set Range1 = Range("A1", ActiveCell.Value)
to keep your titles.

If D is always going to be the rightmost column, you could replace the entire code in the sub with just one line:

ChartObjects("ANA").Chart.SetSourceData Source:=Range("A1:D" & ScrollBar1.Value), PlotBy:=xlColumnswhich eliminates all selecting during the process.
If D isn't always the rightmost column, there are other ways to achieve the same thing.
You could get away with shortening it even more:

ChartObjects("ANA").Chart.SetSourceData Source:=Range("A1:D" & ScrollBar1.Value)

omnibuster
05-20-2010, 11:15 AM
Thanks p45cal.




ChartObjects("ANA").Chart.SetSourceData Source:=Range("A1:D" & ScrollBar1.Value), PlotBy:=xlColumns

Works good.
This was example file.
Now i need to link code in my original file.