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

Sub ConciliacaoBancariaIntegral()
    Dim ws As Worksheet
    Dim lngLinha As Long
    Dim strTipo As String
    Dim curValor As Currency
    Dim curSaldoAcumulado As Currency
    Dim curTotalCreditos As Currency
    Dim curTotalDebitos As Currency
    
    Set ws = ThisWorkbook.Worksheets(1)
    
    Application.ScreenUpdating = False
    
    lngLinha = 2
    curSaldoAcumulado = 0
    curTotalCreditos = 0
    curTotalDebitos = 0
    
    ' Varredura com Do While
    Do While ws.Cells(lngLinha, 1).Value <> ""
        strTipo = UCase(Trim(ws.Cells(lngLinha, 3).Value))
        curValor = CCur(ws.Cells(lngLinha, 4).Value)
        
        If strTipo = "C" Then
            curSaldoAcumulado = curSaldoAcumulado + curValor
            curTotalCreditos = curTotalCreditos + curValor
        ElseIf strTipo = "D" Then
            curSaldoAcumulado = curSaldoAcumulado - curValor
            curTotalDebitos = curTotalDebitos + curValor
        End If
        
        ws.Cells(lngLinha, 5).Value = curSaldoAcumulado
        ws.Cells(lngLinha, 5).NumberFormat = "R$ #,##0.00"
        
        lngLinha = lngLinha + 1
    Loop
    
    ' Linha de Rodapé Executivo (Desafio de Fixação)
    With ws.Range(ws.Cells(lngLinha, 1), ws.Cells(lngLinha, 5))
        .Font.Bold = True
        .Interior.Color = RGB(220, 240, 220)
        .Borders(xlEdgeTop).LineStyle = xlDouble
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
    End With
    
    ws.Cells(lngLinha, 2).Value = "SALDO LÍQUIDO CONCILIADO:"
    ws.Cells(lngLinha, 5).Value = curSaldoAcumulado
    ws.Cells(lngLinha, 5).NumberFormat = "R$ #,##0.00"
    
    ws.Columns("A:E").AutoFit
    Application.ScreenUpdating = True
    
    MsgBox "Conciliação FastLog Concluída!" & vbCrLf & vbCrLf & _
           "• Total Entradas (Créditos): " & FormatCurrency(curTotalCreditos) & vbCrLf & _
           "• Total Saídas (Débitos): " & FormatCurrency(curTotalDebitos) & vbCrLf & _
           "• Saldo Final em Conta: " & FormatCurrency(curSaldoAcumulado), _
           vbInformation, "Tesouraria & Finanças"
End Sub

