Notifications
Clear all

Ajuda Com For Next

5 Posts
2 Usuários
0 Reactions
822 Visualizações
Trindade
(@trindade)
Posts: 278
Reputable Member
Topic starter
 

Boa noite, Srs.

Estou com problema em um For Next, tentando fazer um agrupamento de valor por Ano.
Na Plan("SeriesSimultaneas") esta a minha base de dados mês a mês.
Na Plan("SeriesSimultaneasAno") é pra ser o agrupado por ano.

Montar a série dos anos e as estações esta tranquilo, estou apanhando para realizar a somatória, até consegui fazer isso, mas por algum motivo esta somando errado e não sei onde estou errando e gostaria de uma ajuda dos senhores

Exemplo:
Estação: 1454002
2004 = 1582,1 (Via Código somou certo)
2005 = 804,1 (Na Plan("SeriesSimultaneas") realizando filtro o valor correto é 1.149,9)
2006 = 1009,1 (Na Plan("SeriesSimultaneas") realizando filtro o valor correto é 1.009,1)

Identifiquei que a partir do segundo ano esta deixando de fora o primeiro mês de cada ano, não sei onde estou errando gostaria de uma ajuda dos senhores.

Anexo arquivo:

Qualquer ajuda sempre é bem vinda.

Se a resposta foi útil! Clique na mãozinha ao lado do botão Citar.
Sua dúvida foi respondida? Marque como RESOLVIDO em seus tópicos, usando o botão com marca verde.

 
Postado : 06/03/2016 7:47 pm
(@edcronos2)
Posts: 346
Reputable Member
 

desculpe, madei sem testar, acabel cometendo o mesmo erro seu apesar de ter ficado mais rapido

Sub novoano()
    Dim Li As Long, Lf As Long, Ci As Long, Cf As Long, L2 As Long, Coluno(), ColunD()
    Limpar
    Ci = 1
    Cf = Plan12.Cells(1, Columns.Count).End(xlToLeft).Column

    With Plan13

        With .Range("A1", .Cells(1, Cf))
            .Interior.Color = RGB(192, 192, 192)
            .Font.Color = RGB(0, 0, 0)
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
        End With


        Lf = Plan12.Cells(Rows.Count, 1).End(xlUp).Row + 1
        Coluno = Plan12.Range("A2", Plan12.Cells(Lf, Cf)).Value2
        ct = UBound(Coluno, 2)
        ReDim ColunD(1 To 1, 1 To ct)
        L2 = 1


        For l = 1 To UBound(Coluno, 1)
            If Year(Coluno(l, 1)) = ColunD(1, 1) Then
                For c = 2 To ct
                    ColunD(1, c) = ColunD(1, c) + Coluno(l, c)
                Next

            Else

                .Range(.Cells(L2, 1), .Cells(L2, Cf)).Value2 = ColunD
                L2 = L2 + 1
                For c = 2 To ct
                    ColunD(1, c) = 0
                Next
                ColunD(1, 1) = Year(Coluno(l, 1))
                For c = 2 To ct
                    ColunD(1, c) = ColunD(1, c) + Coluno(l, c)
                Next
            End If

        Next
        .Range("A1", .Cells(1, Cf)).Value2 = Plan12.Range("A1", Plan12.Cells(1, Cf)).Value2
    End With
End Sub

 
Postado : 06/03/2016 9:51 pm
Trindade
(@trindade)
Posts: 278
Reputable Member
Topic starter
 

Bom dia, edcronos2.

Valew, era isso mesmo que estava querendo fazer ... Obrigado!

Se a resposta foi útil! Clique na mãozinha ao lado do botão Citar.
Sua dúvida foi respondida? Marque como RESOLVIDO em seus tópicos, usando o botão com marca verde.

 
Postado : 07/03/2016 5:30 am
(@edcronos2)
Posts: 346
Reputable Member
 

1 for a menos

Sub novoano()
    Dim Li As Long, Lf As Long, Ci As Long, Cf As Long, L2 As Long, Coluno(), ColunD()
    Limpar
    Ci = 1
    Cf = Plan12.Cells(1, Columns.Count).End(xlToLeft).Column

    With Plan13

        With .Range("A1", .Cells(1, Cf))
            .Interior.Color = RGB(192, 192, 192)
            .Font.Color = RGB(0, 0, 0)
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
        End With


        Lf = Plan12.Cells(Rows.Count, 1).End(xlUp).Row + 1
        Coluno = Plan12.Range("A2", Plan12.Cells(Lf, Cf)).Value2
        ct = UBound(Coluno, 2)
        ReDim ColunD(1 To 1, 1 To ct)
        L2 = 1


        For l = 1 To UBound(Coluno, 1)
            If Year(Coluno(l, 1)) = ColunD(1, 1) Then
                For c = 2 To ct
                    ColunD(1, c) = ColunD(1, c) + Coluno(l, c)
                Next
            Else
                .Range(.Cells(L2, 1), .Cells(L2, Cf)).Value2 = ColunD
                L2 = L2 + 1
                ColunD(1, 1) = Year(Coluno(l, 1))
                For c = 2 To ct
                    ColunD(1, c) = Coluno(l, c)
                Next
            End If

        Next
        .Range("A1", .Cells(1, Cf)).Value2 = Plan12.Range("A1", Plan12.Cells(1, Cf)).Value2
    End With
End Sub


 
Postado : 07/03/2016 8:42 am
Trindade
(@trindade)
Posts: 278
Reputable Member
Topic starter
 

Obrigado, edcronos2.

Com um For a menos creio que vá ficar mais rápido, vou usar séries bem extensa.

Mais uma vez obrigado.

Se a resposta foi útil! Clique na mãozinha ao lado do botão Citar.
Sua dúvida foi respondida? Marque como RESOLVIDO em seus tópicos, usando o botão com marca verde.

 
Postado : 07/03/2016 9:08 am