MACRO PARA SOMAR TODAS AS PLANILHAS

ANDERSON.GUIDO

09-06-2010 13:18:51

Primeiramente, Bom dia a todos!!!
Estou com dificuldade na criação de uma macro para somar a mesma célula de todas as planilhas.
Explico melhor:
-criei um invetário de produtos que devem ser baixados diariamente, o resultado é filtrado ao lado da tabela, chamdo de resumo, listado por mês.
-o arquivo em questão não tem um número fixo de planilhas, as quais são criadas conforme a necessidade;
O que preciso realmente é criar uma nova planilha que some em todas as outras planilhas a célula correspondente aos meses, que neste caso são:
R4;S4;T4 (Janeiro)
R5;S5;T5 (fevereiro)
e assin por diante até a
R15;S15;T15.
Porém não sei como escrever esse código.
:?:

webmaster

09-06-2010 16:13:25

Anderson,

Bem vindo. Acho que você pode começar por aqui:

viewtopic.php?f=5&t=259&p=1659#p1659

Se parece muito com o caso.

Abraços

ANDERSON.GUIDO

09-06-2010 16:39:26

webmaster escreveu:Anderson,

Bem vindo. Acho que você pode começar por aqui:

viewtopic.php?f=5&t=259&p=1659#p1659

Se parece muito com o caso.

Abraços
Boa tarde!!!
verifiquei o tópico acima e nele faz a pesquisa de nome de arquivos para ver se são iguais.
estou enviando o arquivo para você ter uma ideia melhor.

webmaster

09-06-2010 19:31:08

Anderson,

Desculpe, agora entendi. No caso, antes de partirmos para as macros, se as planilhas forem iguais, já tentou o recurso Consolidação?

Abraços

ANDERSON.GUIDO

10-06-2010 11:13:00

webmaster escreveu:Anderson,

Desculpe, agora entendi. No caso, antes de partirmos para as macros, se as planilhas forem iguais, já tentou o recurso Consolidação?

Abraços
Bom dia!

A consolidação de dados, ao meu ver, não vai resolver, pois as planilhas são adicionadas conforme a necessidade, não há um numero certo de planilhas.

Assim, uma macro que varresse todas as planilhas somandos as células seria o ideal..

Desde já agradeço a sua atenção

Forte Abraço..

ANDERSON.GUIDO

11-06-2010 16:07:04

ANDERSON.GUIDO escreveu:
webmaster escreveu:Anderson,

Desculpe, agora entendi. No caso, antes de partirmos para as macros, se as planilhas forem iguais, já tentou o recurso Consolidação?

Abraços
Bom dia!

A consolidação de dados, ao meu ver, não vai resolver, pois as planilhas são adicionadas conforme a necessidade, não há um numero certo de planilhas.

Assim, uma macro que varresse todas as planilhas somandos as células seria o ideal..

Desde já agradeço a sua atenção

Forte Abraço..

Boa Tarde!!!!
Depois de muito fazer e errar, consegui escrever esse código
Ficou Bom....
Sub auto_open()
Dim Qtde As Integer, i As Integer
Dim Soma As Double

'soma janeiro
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R4").Value
End If
Next
Sheets("Balancete").Range("B4").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s4").Value
End If
Next
Sheets("Balancete").Range("c4").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t4").Value
End If
Next
Sheets("Balancete").Range("d4").Value = Soma

'SOMA FEVEREIRO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R5").Value
End If
Next
Sheets("Balancete").Range("B5").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s5").Value
End If
Next
Sheets("Balancete").Range("c5").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t5").Value
End If
Next
Sheets("Balancete").Range("d5").Value = Soma

'SOMA MARÇO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R6").Value
End If
Next
Sheets("Balancete").Range("B6").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s6").Value
End If
Next
Sheets("Balancete").Range("c6").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t6").Value
End If
Next
Sheets("Balancete").Range("d6").Value = Soma


'SOMA ABRIL
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R7").Value
End If
Next
Sheets("Balancete").Range("B7").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s7").Value
End If
Next
Sheets("Balancete").Range("c7").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t7").Value
End If
Next
Sheets("Balancete").Range("d7").Value = Soma

'SOMA MAIO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R8").Value
End If
Next
Sheets("Balancete").Range("B8").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s8").Value
End If
Next
Sheets("Balancete").Range("c8").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t8").Value
End If
Next
Sheets("Balancete").Range("d8").Value = Soma

'SOMA JUNHO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R9").Value
End If
Next
Sheets("Balancete").Range("B9").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s9").Value
End If
Next
Sheets("Balancete").Range("c9").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t9").Value
End If
Next
Sheets("Balancete").Range("d9").Value = Soma

'SOMA JULHO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R10").Value
End If
Next
Sheets("Balancete").Range("B10").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s10").Value
End If
Next
Sheets("Balancete").Range("c10").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t10").Value
End If
Next
Sheets("Balancete").Range("d10").Value = Soma


'SOMA AGOSTO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R11").Value
End If
Next
Sheets("Balancete").Range("B11").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s11").Value
End If
Next
Sheets("Balancete").Range("c11").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t11").Value
End If
Next
Sheets("Balancete").Range("d11").Value = Soma

'SOMA SETEMBRO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R12").Value
End If
Next
Sheets("Balancete").Range("B12").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s12").Value
End If
Next
Sheets("Balancete").Range("c12").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t12").Value
End If
Next
Sheets("Balancete").Range("d12").Value = Soma

'SOMA OUTUBRO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R13").Value
End If
Next
Sheets("Balancete").Range("B13").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s13").Value
End If
Next
Sheets("Balancete").Range("c13").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t13").Value
End If
Next
Sheets("Balancete").Range("d13").Value = Soma

'SOMA NOVEMBRO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R14").Value
End If
Next
Sheets("Balancete").Range("B14").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s14").Value
End If
Next
Sheets("Balancete").Range("c14").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t14").Value
End If
Next
Sheets("Balancete").Range("d14").Value = Soma

'SOMA DEZEMBRO
Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("R15").Value
End If
Next
Sheets("Balancete").Range("B15").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("s15").Value
End If
Next
Sheets("Balancete").Range("c15").Value = Soma

Soma = 0
Qtde = Sheets.Count
For i = 1 To Qtde
If Sheets(i).Name <> "Balancete" Then
Soma = Soma + Sheets(i).Range("t15").Value
End If
Next
Sheets("Balancete").Range("d15").Value = Soma


End Sub

webmaster

11-06-2010 17:37:47

Anderson,

Vou insistir mais uma vez no recurso Consolidação. Fiz um teste aqui e deu muito certo. Anexo coloco o exemplo e abaixo um link com a explicação:

http://office.microsoft.com/pt-br/excel ... 24663.aspx

Abraços e espero que ajude