Adicionado em: | 10/11/2011 |
Modificado em: | 10/11/2011 |
Tamanho: | Vazio |
Downloads: | 933 |
Saberexcel - o site das macros microsoft Excel VBA
Esses procedimentos do aplicativo Microsoft Excel VBA ligados ao Evento de planilha WorsheetChange, insere soma de determinada planilha,
selecionada na lista Validação de Dados, esse valor é retornado pelo Evento Change e também, fiz um macro ligado a uma combobox (Ferramentas formulário), o mesmo macro retornando a soma de da coluna(1) de determinada Planilha.
Observe que para que o macro execute as somas fiz uso das poderosas WorksheetFunctions, "Funções de Planilha".
Não deixe de Ver nosso Trabalho com As WorkheetFunctions, são 340 Planilhas Worksheetfunctions exemplos vba para treinamentos.
Excel planilha wkf worksheetfunction funções de planilhas retornam valores vba
NO MODULO DA FOLHA DE PLANILHA (PLAN1) INSERIRA o procedimento com
o Evento Worksheet_Change
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" And Target.Count = 1 Then
X = Application.WorksheetFunction.Sum(Plan1.Range("A:A"))
b = Application.WorksheetFunction.Sum(Plan2.Range("A:A"))
d = Application.WorksheetFunction.Sum(Plan3.Range("A:A"))
e = Application.WorksheetFunction.Sum(Plan4.Range("A:A"))
If Target.Value = "Plan1" Then
Plan1.[C2].Value = X
ElseIf Target.Value = "Plan2" Then
Plan1.[C2].Value = b
ElseIf Target.Value = "Plan3" Then
Plan1.[C2].Value = d
ElseIf Target.Value = "Plan4" Then
Plan1.[C2].Value = e
End If
[c9].FormulaLocal = _
"=""Soma da Coluna(A) [ "" & C1 & "" ] Total....[ R$ "" &c2 & "" ]"""
[c12].Value = ""
[sbx].Value = ""
End If
End Sub
'- - - - - - - - - - - -
EM UM MÓDULO COMUM..
Usando os mesmos códigos acima fizemos um macro para ligá-lo a um combobox independente, usamos aqui um objeto combobox da barra de Ferramenta formulários.
Sub sbx_inserir_soma_planilhas_combobox()
X = Application.WorksheetFunction.Sum(Plan1.Range("A:A"))
b = Application.WorksheetFunction.Sum(Plan2.Range("A:A"))
d = Application.WorksheetFunction.Sum(Plan3.Range("A:A"))
e = Application.WorksheetFunction.Sum(Plan4.Range("A:A"))
If [alvo].Value = "Plan1" Then 'observque que renomeei uma célula na folha de planilha pelo nome de 'alvo' e outra 'sbx'
[sbx].Value = X
ElseIf [alvo].Value = "Plan2" Then
[sbx].Value = b
ElseIf [alvo].Value = "Plan3" Then
[sbx].Value = d
ElseIf [alvo].Value = "Plan4" Then
[sbx].Value = e
End If
[c12].FormulaLocal = _
"=""Soma da Coluna(A) [ "" & alvo & "" ] Total....[ R$ "" &sbx & "" ]"""
[c9].Value = ""
[C2].Value = ""
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.
Adquira já o Acesso Imediato
à Area de Membros
Aprenda Excel VBA com Simplicidade de
códigos e Eficácia, Escrevendo Menos e
Fazendo Mais.
'-------------------------------------'
Entrega Imediata:
+ 500 Video Aulas MS Excel VBA
+ 35.000 Planilhas Excel e VBA
+ Coleção 25.000 Macros MS Excel VBA
+ 141 Planilhas Instruções Loops
+ 341 Planilhas WorksheetFunctions(VBA)
+ 04 Módulos Como Fazer Excel VBA
+ Curso Completo MS Excel VBA
+ Planilhas Inteligentes
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2317234650173689";
/* retangulo 336 x 280 */
google_ad_slot = "0315083363";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Aprenda tudo sobre o Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Saberexcel,
Sobre as WorksheetFunctions Funções de Planilhas que retornam valores do VBA