Boa tarde Pessoal.
Estou gerando um relatório em VBA, mas não consigo e nem faço ideia, de como totalizar no final os valores do relatório.
"Cells(linha, 4) = RSt2("VALORES")" neste célula que gostaria de totalizar no meu relatório. Não sei como fazer isso.
Este é o comando completo que gero o relatório
Set Db2 = OpenDatabase(ThisWorkbook.Path & "\" & ThisWorkbook.Name, False, False, "Excel 8.0")
Set RSt2 = Db2.OpenRecordset("SELECT DEB, CTDEB, VALORES FROM (SELECT DEB, CTDEB, SUM (VALORE) AS VALORES FROM (SELECT DÉBITO AS DEB, CONTA_DEB AS CTDEB, SUM(VALOR)*-1 AS VALORE FROM [Diário$] Where Débito < 2000000 GROUP BY DÉBITO, CONTA_DEB UNION
SELECT CRÉDITO AS DEB, CONTA_CRED, SUM(VALOR) AS VALORE FROM [Diário$] Where Crédito < 2000000 GROUP BY CRÉDITO, CONTA_CRED ) GROUP BY DEB, CTDEB) WHERE VALORES <> 0")
'define em qual linha começar:
linha = 2
'enquanto não houver erro:
While Not RSt2.EOF
linha = linha + 1
Cells(linha, 2) = RSt2("DEB")
Cells(linha, 3) = RSt2("CTDEB")
Cells(linha, 4) = RSt2("VALORES")
RSt2.MoveNext
Wend
Grande abaixo a todos