+ Reply to Thread
Results 1 to 2 of 2

Cálculo de MÉDIA com VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    São Paulo, Campinas
    MS-Off Ver
    Excel 2010
    Posts
    2

    Cálculo de MÉDIA com VBA

    Bom dia,
    Estou com um problema na planilha onde tenho que controlar a frota da empresa.
    Tenho que calcular a média dos KMs rodados, valor médio gasto em R$ e valor médio abastecido por cada veículo.
    Consegui montar alguma coisa, já estou conseguindo o filtro, pesquisa por placa de cada veículo, falta o cálculo da média, estou tentando colocar na frente de cada placa na linha marcada em amarelo, o que acho complicado, ou nas ultimas colunas da direita, alguém poderia me ajudar?
    abaixo esta o código que fiz até o momento:

    Segue o link da mesma planilha no GOOGLE DRIVE:
    https://drive.google.com/file/d/0By4...it?usp=sharing

    Em anexo esta uma planilha de exemplo com o código abaixo.

    Sub sbx_separar_classificar_somar()
    Dim tSoma As Double
    Plan2.[1:1000].Delete
    Plan3.Range("A1").CurrentRegion.Copy [a1]
    Range("C1").CurrentRegion.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlGuess
    i = 2
    Do While Cells(i, "D") <> ""
    sbcateg = Cells(i, "D")
    Rows(i).Insert
    Cells(i, "D") = sbcateg
    Cells(i, "a").Resize(, 18).Interior.ColorIndex = 6
    Cells(i, "a").Resize(, 18).Merge
    Cells(i, "a").Font.Bold = True
    Cells(i, "a").Resize(, 18).HorizontalAlignment = xlCenter
    ' Range("A" & CStr(i)).HorizontalAlignment = xlCenter
    i = i + 1
    
    'CALCULA MÉDIA DE KILOMETROS, COLUNA I
    Do While Cells(i, "D") = sbcateg
    tSoma = tSoma + Cells(i, "I").Value
    i = i + 1
    Loop
    Cells(i - 1, "S").Value = tSoma
    tSoma = 0
    
    'CALCULA MÉDIA DE LITROS, COLUNA M
    Do While Cells(i, "D") = sbcateg
    RSoma = RSoma + Cells(i, "M").Value
    i = i + 1
    Loop
    Cells(i - 1, "T").Value = RSoma
    RSoma = 0
    
    'CALCULA MÉDIA DE GASTO EM REAIS, COLUNA P
    Do While Cells(i, "D") = sbcateg
    RSoma = RSoma + Cells(i, "P").Value
    i = i + 1
    Loop
    Cells(i - 1, "U").Value = RSoma
    RSoma = 0
    
    Loop
    End Sub
    Sub sbx_limpar_teste()
    Plan2.[1:1000].Delete
    msgbox ("Dados foram deletados com sucesso!"), vbInformation, "CONTROLE DE FROTA"
    End Sub
    Sub sbx_mensagem()
    msgbox ("Por favor clique na vassourinha, rs....."), vbCritical, "CONTROLE DE FROTA"
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. Also, moved from Excel Programming / VBA / Macros --6StringJazzer
    Last edited by 6StringJazzer; 02-03-2014 at 03:33 PM.

  2. #2
    Registered User
    Join Date
    02-03-2014
    Location
    São Paulo, Campinas
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Cálculo de MÉDIA com VBA

    Obrigado pela ajuda, desculpe pela postagem em local incorreto....vou fazer a leitura das regras e obrigado pela aoportunidade

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Windows Media Player
    By zaky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2013, 03:38 PM
  2. Way to Go Virgin Media!
    By TMS in forum The Water Cooler
    Replies: 14
    Last Post: 07-13-2012, 07:07 AM
  3. [SOLVED] Media Player versus Windows Media Player
    By teepee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-15-2005, 02:05 PM
  4. Media Player versus Windows Media Player
    By teepee in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 10:05 PM
  5. Media Player versus Windows Media Player
    By teepee in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 10:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1