Hi All
I have managed to get a scrolling chart together utilising VBA. The Y axis (dates) scrolls as I had hoped AND I was able to retain the resolution that I was after.
The problem I have now is that the X axis labels are fixed and I am unable to work out how to apply a similar treatement.
Currently the X axis labels are defined by:
[pre]
Code:
Dim Max As String
Dim Min As String
Max = ActiveSheet.Range("$AH$1")
Min = ActiveSheet.Range("$AH$2")
where:
[pre][code]$AH$1 =ROUNDUP(MAX(AF5:AF34,AK5:AK34,AL5:AL34),2)
$AH$2 =ROUNDDOWN(MIN(AG5:AG34,AK5:AK34,AL5:AL34),2)
and then applied:
With ActiveChart.Axes(xlValue)
.MinimumScale = Min
.MaximumScale = Max
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
[/pre]
When scrolling through the period the Min and Max updated on the spread sheet accordingly, but this update is not reflected in the chart X axis.
Would anyone be aware of how to make this automatically update also?
For anyone who may have wondered the same thing, here is the code I used to make the scrolling Y axis work. Please note, this will not work in the previously attached example file with out modification. If requested I will update the example file a upload.
The code is not pretty, but functional:
Dim eDate As Date
Dim sDate As Date
Dim rngRes As String
Dim rngNum As String
Dim rngScroll As String
Dim eCell As String
Dim FillRes As String
Dim Fill As String
eDate = ActiveSheet.Range("$A$5"
'End date of chart period
sDate = chart_period_date 'Start date of chart period
rngRes = Application.WorksheetFunction.NetworkDays(sDate, eDate) 'Number of weekdays
rngNum = Worksheets(Stock).Range("A:A"
.Cells.SpecialCells(xlCellTypeConstants).Count 'total number of cells in date colum (inc. header)
rngScroll = rngNum - rngRes 'Ensures no "blank" data is displayed
eCell = "=INDEX([" & Stock & ".xlsx]" & Stock & "!A5:A" & rngScroll + 4 & ",$AE$1)"
Windows("Share Trading.xlsm"
.Activate
Sheets("ASXCharts"
.Select
ActiveSheet.Range("$AE$1"
.Select
ActiveCell.FormulaR1C1 = rngScroll
ActiveSheet.Range("AD5"
.Select
ActiveSheet.Shapes.Range(Array("Scroll Bar 15"
).Select
With Selection
.Value = 1
.Min = 1
.Max = rngScroll
.SmallChange = 1
.LargeChange = rngRes
.LinkedCell = "$AE$1"
.Display3DShading = True
End With
ActiveSheet.Range("$AD$5"
.Select
ActiveCell.Formula = eCell
Range("AD5"
.Select
Application.CutCopyMode = False
Worksheets("ASXCharts"
.Range("AD5:BD5"
.FillRight
Range("AD5"
.Select
Selection.NumberFormat = "m/d/yyyy"
Range("AE5:BD5"
.Select
Selection.NumberFormat = "General"
Range("AD5:BD5"
.Select
FillRes = rngRes + 12
Worksheets("ASXCharts"
.Range("AA5:BA" & FillRes).FillDown[/code][/pre]
Cheers
Shaun