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

Sub TotalizarRetencoesFiscais()
    Dim ws As Worksheet
    Dim lngLinhaFinal As Long
    Dim i As Long
    Dim arrRetidos() As String
    Dim intContador As Long
    Dim strRelatorio As String
    
    Set ws = ThisWorkbook.Worksheets(1)
    lngLinhaFinal = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    intContador = 0
    
    For i = 2 To lngLinhaFinal
        If UCase(Trim(ws.Cells(i, 5).Value)) = "RETIDO" Then
            intContador = intContador + 1
            ReDim Preserve arrRetidos(1 To intContador)
            arrRetidos(intContador) = ws.Cells(i, 2).Value & " (" & ws.Cells(i, 4).Value & ")"
        End If
    Next i
    
    If intContador = 0 Then
        MsgBox "Nenhum veículo retido pela fiscalização!", vbInformation, "Posto Fiscal Liberado"
    Else
        strRelatorio = "ALERTA DE VEÍCULOS RETIDOS NA SEFAZ (" & intContador & " carretas):" & vbCrLf & vbCrLf
        For i = 1 To intContador
            strRelatorio = strRelatorio & "• " & arrRetidos(i) & vbCrLf
        Next i
        
        MsgBox strRelatorio, vbExclamation, "Auditoria Fiscal FastLog"
    End If
    
    Erase arrRetidos
End Sub

