VBA to resize multiple Chart Series via A Scrollbar.

NatetheGreat

Active Member
Joined
Nov 18, 2013
Messages
268
Hello,

I currently have a beautiful bit of code assigned to a scrollbar, that was suggested to me here on Mr.Excel. Thanks to all the Gurus out their for their continual support and assistance.
Code:
Sub Scrollbar1_Change()
Select Case ActiveSheet.ScrollBars("Scroll bar 3").Value
Case "0"
Call FullChartDataRange
Case "1"
Call HalfChartDataRange
Case "2"
Call QuarterChartDataRange
Case "3"
Call eighthChartDataRange
Case "4"
Call SixteenthChartDataRange
End Select
End Sub

Each of these cases call a very similar sub, which are just resizing the range of a series on the active chart
Code:
Sub HalfChartDataRange()
Dim Rng As Range
    
    ActiveSheet.ChartObjects("Rolling Position").Activate
    Set Rng = Sheets("Raw Data").Range("Stats[RollPos]")
    ActiveChart.SetSourceData Source:=Rng.Resize(Rng.Rows.Count / 2)
    
End Sub
Sub QuarterChartDataRange()
Dim Rng As Range
ActiveSheet.ChartObjects("Rolling Position").Activate
Set Rng = Sheets("Raw Data").Range("Stats[RollPos]")
    ActiveChart.SetSourceData Source:=Rng.Resize(Rng.Rows.Count / 4)
End Sub

there are 5 in all... each of these adjusting the range of the chart to different sections of the data series.

this works great, but does anyone know what the code would be to apply the same logic to a different chart which had not just one, but 3 series within it? All three series are linked to the same table which the same x-axis values, just looking to adapt

Code:
  Set Rng = Sheets("Raw Data").Range("Stats[RollPos]")
    ActiveChart.SetSourceData Source:=Rng.Resize(Rng.Rows.Count / 2)

So that it will re-size (split in half) three series instead of just the one.


Thanks so much !
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
What is the source for the chart?


Andrew,

The source for the chart would be on the same table "Raw Data", it gets created via the following code which may be helpful
Code:
 ActiveChart.SeriesCollection.Add _
        Source:=Worksheets("Raw Data").Range("Stats[[#All],[Cum Bid]]")
    
ActiveChart.SeriesCollection.Add _
        Source:=Worksheets("Raw Data").Range("Stats[[#All],[Cum Ask]]")

so in total their are three series, all in the stats table

1)Cum Ask, 2)Cum Bid, 3)Rolling Position
 
Upvote 0
Rolling PositionCumOffrCumBidCellRef
324101
426152
527163
622174
515195
414206
313127
211138
1899

<TBODY>
</TBODY>

So You can Imagine I have my chart that has these three series plotted on it. The cellref is the x-axis. Say the user wanted to show just the first 5 values (i.e. cell ref 1-5 and corresponding series values), that is the purpose of resizing via the scrollbar.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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