' === Pratica Obrigatoria 1 (ATIVO) ===
Option Explicit

Sub CalcularMediaPonderadaConsumo()
    Dim ws As Worksheet
    Dim varMatriz As Variant
    Dim r As Long
    Dim dblSomaKm As Double
    Dim dblSomaLitros As Double
    Dim dblMediaGlobal As Double
    Dim lngLinhas As Long
    
    Set ws = ThisWorkbook.Worksheets(1)
    lngLinhas = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    If lngLinhas < 2 Then Exit Sub
    
    varMatriz = ws.Range("A2:E" & lngLinhas).Value
    dblSomaKm = 0
    dblSomaLitros = 0
    
    For r = 1 To UBound(varMatriz, 1)
        dblSomaKm = dblSomaKm + CDbl(varMatriz(r, 3))
        dblSomaLitros = dblSomaLitros + CDbl(varMatriz(r, 4))
    Next r
    
    If dblSomaLitros > 0 Then
        dblMediaGlobal = dblSomaKm / dblSomaLitros
    Else
        dblMediaGlobal = 0
    End If
    
    MsgBox "MÉDIA GLOBAL DE CONSUMO FASTLOG:" & vbCrLf & vbCrLf & _
           "• Total de Km Percorridos: " & FormatNumber(dblSomaKm, 0) & " km" & vbCrLf & _
           "• Total de Diesel Consumido: " & FormatNumber(dblSomaLitros, 0) & " litros" & vbCrLf & _
           "• Média Ponderada da Frota: " & Format(dblMediaGlobal, "0.00") & " km/L", _
           vbInformation, "Indicador Estratégico ESG"
End Sub

