Changing the graph window pane through scroll bar using excel VBA macro

dexter1584

New Member
Joined
Nov 26, 2013
Messages
1
Hi All

Can someone please help me with this requirement. I want to write a excel VBA macro which is to be used for all the open excel worksheets. Macro should make a line chart between any two columns of data in sheet1 and draw it on sheet2 of same worksheet. Also, there needs to be a scroll bar linked to the line chart using which one can scroll though the graph. basically i want the graph to show only a portion of data series at once but it needs to have the ability to scroll through the remaining data using scroll bar. My current macro looks something like this :-

Sub Test()
Dim intPoints As Integer
intPoints = Cells(Rows.Count, 2).End(xlUp).Row
' create the chart
Sheets("Sheet2").Select
ActiveSheet.ChartObjects.Add Left:=50, Top:=50, Width:=300, Height:=300
With ActiveSheet.ChartObjects(1).Chart
.ChartType = xlLine
' create series
.SeriesCollection.NewSeries

Sheets("Sheet1").Select
With .SeriesCollection(1)
.Name = ActiveSheet.Range("B1").Value
.XValues = ActiveSheet.Range("A2:A" & intPoints)
.Values = ActiveSheet.Range("B2:B" & intPoints)
.AxisGroup = xlPrimary
End With

.SeriesCollection.NewSeries
With .SeriesCollection(2)
.Name = ActiveSheet.Range("C1").Value
.XValues = ActiveSheet.Range("A2:A" & intPoints)
.Values = ActiveSheet.Range("C2:C" & intPoints)
.AxisGroup = xlSecondary
End With
ActiveSheet.ScrollBars.Add(366, 6.75, 429.75, 22.5).Select
With Selection
.Value = 0
.Min = 0
.Max = 30000
.SmallChange = 1
.LargeChange = 1
.LinkedCell = "$A$2"
.Display3DShading = True
End With
.HasAxis(xlValue, xlPrimary) = True
.HasAxis(xlValue, xlSecondary) = True

End With
End Sub


Any help would be appreciated.

Thanks in advance.
Dexter
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,326
Messages
6,124,272
Members
449,149
Latest member
mwdbActuary

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