Show dates on chart vba

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I'm using the below to graph data. How can I include the dates on the graph?


VBA Code:
Sub PLineChart()
Dim MyChart As Chart
Dim FName As String
Dim LRow As Long, Rng As Range, i As Long

With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
End With

Set Wks = ActiveSheet
Set MyChart = Wks.Shapes.AddChart(xlLine).Chart
Set Rng = Range("A6", Range("A" & Rows.Count).End(xlUp)).Resize(, 18)

If Rng.Rows.Count > 1 Then
    Rng.AdvancedFilter xlFilterCopy, Range("T2:U3"), Range("BI6:BJ6"), Unique:=False
End If
LRow = Application.CountA(Range("BJ:BJ")) + 5

For i = 7 To LRow
    Range("BK" & i) = Format(Application.Sum(Range("BJ7:BJ" & i)), "$#,0.00")
Next

With MyChart
    .ChartArea.Height = 190
    .ChartArea.Width = 312
    .PlotVisibleOnly = False
    .SeriesCollection(1).Format.Line.Weight = 1
    .SetSourceData Source:=ActiveSheet.Range("BK7:BK" & LRow)
    If Application.Subtotal(2, ActiveSheet.Range("BK7:BK" & LRow)) = 1 Then
        .SeriesCollection(1).MarkerStyle = xlMarkerStyleCircle
    End If
    .Axes(xlCategory).MajorTickMark = xlNone
    .Axes(xlCategory).TickLabelPosition = xlNone
    .Axes(xlValue).TickLabels.NumberFormat = "$#,##0_);[Red]($#,##0)"
    .Legend.Delete
End With

FName = Environ("temp") & "\temp.gif"
MyChart.Export Filename:=FName, FilterName:="GIF"
frmData.iChart.Picture = LoadPicture(FName)
Wks.ChartObjects(1).Delete
Kill FName

With Wks
    .Range("T3:U3").Clear
    .Range("BI7:BK" & LRow).Clear
End With

With Application
    .Calculation = xlCalculationAutomatic
    .EnableEvents = True
    .ScreenUpdating = True
End With
End Sub

1593996879897.png
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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