Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,074
- Office Version
- 2019
- Platform
- Windows
The code below display data in either a weekly graph or monthly graph. I would like to edit this code to include a daily graph. Can someone assist with my request.
Thank you kindly.
Thank you kindly.
VBA Code:
Function PLData(Optional returnValues As Boolean = False) As Variant
Dim lastRow&, i&, dataType$
Dim a, d, k As Variant
Dim r As Range, c As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
lastRow = Wks.Cells(Wks.Rows.Count, 11).End(xlUp).Row - 6
If lastRow <= 1 Then
frmData.iChart.Picture = LoadPicture("")
MsgBox "No Data Found or Not Enough Data.", vbInformation, "Traderking - Trade Journal"
End
End If
dataType = UCase(frmData.lbCandles)
Set d = CreateObject("Scripting.Dictionary")
Set r = Wks.Range("K7").Resize(lastRow)
For Each c In r.SpecialCells(xlCellTypeVisible)
If IsDate(c.Value) Then
If dataType = "WEEKLY" Then
k = Format(Application.Max(DateSerial(Year(c.Value), Month(c.Value), Day(c.Value)) - Weekday(c.Value, 2), DateSerial(Year(c.Value), 1, 1)), "'mmm-dd")
Else
k = Format(c.Value, "mmm")
End If
If Not d.exists(k) Then d.Add k, 0#
d(k) = d(k) + c.Offset(, 6).Value
End If
Next c
If d.Count > 0 Then
ReDim a(1 To d.Count + 1, 1 To 3)
a(1, 1) = "Period": a(1, 2) = "Start": a(1, 3) = "Finish"
i = 1
For Each k In d.keys
i = i + 1
a(i, 1) = k
If i > 2 Then a(i, 2) = a(i - 1, 3) Else a(i, 2) = 0
a(i, 3) = a(i, 2) + d(k)
Next k
If Not returnValues Then PLWaterfall a
Else
frmData.iChart.Picture = LoadPicture("")
MsgBox "No Data Found or Not Enough Data.", vbInformation, "Traderking - Trade Journal"
End
End If
Set d = Nothing
Set Wks = Nothing
Set r = Nothing
PLData = a
End Function