-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXCEL_CHART_MOVING_AVG_LIBR.bas
executable file
·86 lines (76 loc) · 3.24 KB
/
EXCEL_CHART_MOVING_AVG_LIBR.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Attribute VB_Name = "EXCEL_CHART_MOVING_AVG_LIBR"
'--------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------
Option Explicit 'Requires that all variables to be declared explicitly.
Option Base 1 'The "Option Base" statement allows to specify 0 or 1 as the
'default first index of arrays.
'--------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------
'************************************************************************************
'************************************************************************************
'FUNCTION : EXCEL_CHART_MOVING_AVERAGE_FUNC
'DESCRIPTION :
'LIBRARY : EXCEL_CHART
'GROUP :
'ID : 001
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'************************************************************************************
'************************************************************************************
' Procedure to show moving avg for user specified period
' Cycles through all charts, applies same criteria to each chart
'///////////////////////////////////////////////////////////////////
'User choices:
'1.Show data series?
'2.Moving Avg Period? If 0, no moving avg
'///////////////////////////////////////////////////////////////////
Function EXCEL_CHART_MOVING_AVERAGE_FUNC(ByRef CHART_OBJ As Excel.Chart, _
Optional ByVal MA_PERIOD As Long = 2, _
Optional ByVal DISPLAY_FLAG As Boolean = True)
'DISPLAY_FLAG --> Data Display On/Off
Dim i As Long
Dim j As Long
Dim k As Long
Dim NSIZE As Long
On Error GoTo ERROR_LABEL
EXCEL_CHART_MOVING_AVERAGE_FUNC = False
'Set moving Averages
With CHART_OBJ
NSIZE = .SeriesCollection.COUNT
' Remove previous trendlines
' Check to see how many trend lines
For i = 1 To NSIZE
j = .SeriesCollection(i).Trendlines.COUNT
If j > 0 Then
For k = 1 To j: .SeriesCollection(i).Trendlines(k).Delete: Next k
End If
If MA_PERIOD >= 2 Then ' Check to see if period > 0; if yes, add trend line
With .SeriesCollection(i)
k = .Points.COUNT
With .Trendlines.Add(Type:=xlMovingAvg, PERIOD:=MA_PERIOD, FORWARD:=0, Backward:=0, _
DisplayEquation:=False, DisplayRSquared:=False)
With .Border
.ColorIndex = 10
.WEIGHT = xlMedium
.LineStyle = xlHairline
End With
End With
End With
End If
If DISPLAY_FLAG = False Then ' Check to see if data series to be plotted
With .SeriesCollection(i).Border
.WEIGHT = xlHairline
.LineStyle = xlNone
End With
Else
With .SeriesCollection(i).Border
.WEIGHT = xlThin
.LineStyle = xlAutomatic
End With
End If
Next i
End With
EXCEL_CHART_MOVING_AVERAGE_FUNC = True
Exit Function
ERROR_LABEL:
EXCEL_CHART_MOVING_AVERAGE_FUNC = False
End Function