Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#14433
Pessoal, preciso da ajuda de vocês.
Venho tentando criar um loop pra, em uma planilha, na mesma coluna, quando um valor é encontrado, adicionar este valor a soma até o final do loop. Vejam a imagem abaixo, a coluna em questão é a "D" e o valor é o abaixo de "DIAS DECORRIDOS", ou seja, quando encontrar este texto, deveria adicionar os números à soma.

Imagem

Eu já tentei várias coisas mas eu não consigo realizar esta façanha.
Enfim, o que fiz foi o seguinte:
Código: Selecionar todos
Sub incluir()
Dim emptyrow As String
Dim i As Long
Dim soma As String

emptyrow = Range("A65536").End(xlUp).Offset(1, 0).Row
soma = 0
For i = 0 To emptyrow
If (i <= 9) Then
soma = Range("d" & 9).Value
End If
If (i > 9) Then
soma = soma + Range("d" & 9).Value
End If
MsgBox soma
i = i + 9
Next i

    
End Sub
Sei que está errado pois não funciona, então preciso muito da ajuda de vocês.

Um abraço!
#14496
Não sei se entendi, mas experimente
Código: Selecionar todos
Sub incluir()
Dim i As Long
Dim soma As Long
soma = 0
For i = 0 To Cells(Cells.Rows.Count, "A").End(xlUp).Row
    If Cells(i, "D") = "DIAS DECORRIDOS" Then
        soma = soma + Cells(i + 1, "D").Value
        End If
    MsgBox soma
Next i
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord