Excel planilha wkf somar planilhas validacao dados

Qui, 10 de Novembro de 2011 14:43 Expedito Marcondes
Imprimir

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.



   Baixe o exemplo de planilha contendo os macros e procedimentos acima
Excel planilha wkf somar planilha validacao dados (92.58 KB)

Tags:
Última atualização em Qui, 10 de Novembro de 2011 15:06