Graph VBA Problem

Av8tordude

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

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
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