Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
I have this code that I used on another project. I tried to adjust the code on a project I'm working on however, I can't seem to figure out why its not working. The first project, my dates were in column A, however my new project has the dates in column D. Can anyone assist to help me figure out what the problem is. Thanks
Code:
Sub Graph()Dim D, i As Long, n As Long, w(), dic As Object, r(), minDt, maxDt
Dim dFlg As Boolean, acFlg As Boolean, fcCol, x, lDt, fDt
fcCol = Array(16)
If cbMon <> "All Positions" Then
With Sheets("Options").Range("D1001")
.Formula = "=MIN(Options!D15:D1001)"
minDt = .Value
.Formula = "=MAX(Options!D15:D1001)"
maxDt = .Value
.ClearContents
End With
'If CDate(txtSDate) < minDt Then
' MsgBox "The First Options Entry Date is: " & Format(minDt, "dd-mmm-yy"), vbInformation, "FlightLog - Professional Edition"
' txtSDate = minDt
'End If
'If CDate(txtEDate) > maxDt Then
' MsgBox "The Last Options Entry Date is: " & Format(maxDt, "dd-mmm-yy"), vbInformation, "FlightLog - Professional Edition"
' txtEDate = maxDt
'End If
dFlg = True
End If
If Len(cbMonth) <> "All Positions" Then
With Sheets("Options")
D = .Range("A15:Q" & Application.Max(15, .Range("A" & Rows.Count).End(xlUp).Row))
End With
Set dic = CreateObject("scripting.dictionary")
dic.comparemode = vbTextCompare
x = fcCol(fcIdx)
ReDim w(1 To UBound(D, 1), 1 To 2)
For i = 1 To UBound(D, 1)
If Not IsEmpty(D(i, 1)) Then
If Not dic.exists(Year(D(i, 1))) Then
n = n + 1
w(n, 1) = Year(D(i, 1)): w(n, 2) = w(n, 2) + D(i, x)
dic.Add Year(D(i, 1)), Array(n, 2)
Else
r = dic.Item(Year(D(i, 1)))
w(r(0), 2) = w(r(0), 2) + D(i, x)
dic.Item(Year(D(i, 1))) = r
End If
End If
Next
End If
If n > 0 Then
With Range("R15")
.Value = "Year"
.Offset(, 1).Value = cbMon
'.Offset(, 2).Value = IIf(acFlg, cbAC, "Flight Conditions")
.Offset(1).Resize(n).NumberFormat = "#"
.Offset(1).Resize(n, 2).Value = w
'.Offset(1).Resize(n).Name = "xValues"
'.Offset(1, 1).Resize(n).Name = "yValues"
End With
Erase D
Set dic = Nothing
End If
End Sub