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