Edit code to include plotting daily graph

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. 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.

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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hello
I think it is better to attach a sample file (without sensitive data).
Hello,
Mario
 
Upvote 0

Forum statistics

Threads
1,215,655
Messages
6,126,050
Members
449,283
Latest member
GeisonGDC

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