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
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