DONUT PROJECT - VBA - Criando uma Matriz de Datas MAT - Moving Annual Total


Em diversas ocasiões usamos tabelas com períodos MAT, geralmente estas são extraídas de BIs (Business Information). Os cabeçalhos nem sempre são aquilo que desejaríamos usar.





Como podemos conciliar o conteúdo, adequando os títulos?




As funções abaixo lhe permitirão carregar (LoadMonths()) em uma Matriz, 12 meses, sendo o primeiro uma data passada e os próximos 11 meses serão calculados retroativamente. Depois poderão recuperar (ReturnMonth()) estas datas.


Global nMeses(12) As Date

Sub LoadMonths()
    '      Author: André Bernardes
    '        Date: 20/08/14 - 09:53
    '      Action: Cria tabelas de Regionais para análise.
    ' Application: Analysis****Regional®
    '   Test line: nMeses (1), nMeses(2), nMeses(3), nMeses(4), nMeses(5), nMeses(6), nMeses(7), nMeses(8), nMeses(9), nMeses(10), nMeses(11), nMeses(12)
    '   Test line: Debug.Print ReturnMonth(1), ReturnMonth(2), ReturnMonth(3), ReturnMonth(4), ReturnMonth(5), ReturnMonth(6), ReturnMonth(7), ReturnMonth(8), ReturnMonth(9), ReturnMonth(10), ReturnMonth(11), ReturnMonth(12)

    Dim i As Integer
    Dim Flag As Boolean
    Dim LastDate As Date

    Let Flag = True

    For i = 1 To 12
        If Flag Then
            Let nMeses(i) = Sheets("Analise").Range("I5").Value
            Let LastDate = nMeses(i)
            Let Flag = False
        Else
            Let nMeses(i) = DateAdd("m", -1, LastDate)
            Let LastDate = nMeses(i)
        End If
    Next
End Sub

Function ReturnMonth (nMnth As Integer) As String
    '      Author: André Bernardes
    '        Date: 20/08/14 - 09:53
    '      Action: Cria tabelas de Regionais para análise.
    ' Application: AnalysisMDTRRegional®
    '   Test line: nMeses (1), nMeses(2), nMeses(3), nMeses(4), nMeses(5), nMeses(6), nMeses(7), nMeses(8), nMeses(9), nMeses(10), nMeses(11), nMeses(12)
    '   Test line: Debug.Print ReturnMonth(1), ReturnMonth(2), ReturnMonth(3), ReturnMonth(4), ReturnMonth(5), ReturnMonth(6), ReturnMonth(7), ReturnMonth(8), ReturnMonth(9), ReturnMonth(10), ReturnMonth(11), ReturnMonth(12)

    Dim nMonth As String
    Dim nYear As String
    Dim nTitle01 As String

    Let nMonth = Mid(Format(nMeses(nMnth), "DD/MM/YYYY"), 4, 2)
    Let nYear = Year(nMeses(nMnth))
    Let nTitle01 = UCase(Left(Format(Month(nMonth), "mmm"), 3))

    If nMonth = "01" Then
        Let ReturnMonth = "JAN|" & nYear
    ElseIf nMonth = "02" Then
        Let ReturnMonth = "FEV|" & nYear
    ElseIf nMonth = "03" Then
        Let ReturnMonth = "MAR|" & nYear
    ElseIf nMonth = "04" Then
        Let ReturnMonth = "ABR|" & nYear
    ElseIf nMonth = "05" Then
        Let ReturnMonth = "MAI|" & nYear
    ElseIf nMonth = "06" Then
        Let ReturnMonth = "JUN|" & nYear
    ElseIf nMonth = "07" Then
        Let ReturnMonth = "JUL|" & nYear
    ElseIf nMonth = "08" Then
        Let ReturnMonth = "AGO|" & nYear
    ElseIf nMonth = "09" Then
        Let ReturnMonth = "SET|" & nYear
    ElseIf nMonth = "10" Then
        Let ReturnMonth = "OUT|" & nYear
    ElseIf nMonth = "11" Then
        Let ReturnMonth = "NOV|" & nYear
    ElseIf nMonth = "12" Then
        Let ReturnMonth = "DEZ|" & nYear
    End If
End Function

Caso queiram traduzir os meses para outros idiomas basta que alterem os meses.


 Série eBook Donut Projects: 

DONUT PROJECT: VBA - Projetos e Códigos de Visual Basic for Applications (Visual Basic For Apllication)eBook - DONUT PROJECT 2024 - Volume 03 - Funções Financeiras - André Luiz Bernardes eBook - DONUT PROJECT 2024 - Volume 02 - Conectando Banco de Dados - André Luiz Bernardes eBook - DONUT PROJECT 2024 - Volume 01 - André Luiz Bernardes



Conheça também:

DONUT PROJECT 2021 - VBA Function:  Como Rastrear o Google Maps (Coordenadas Geográficas) no VBA Excel?

DONUT PROJECT 2021 - VBA Function:  Crie Acrônimos a partir de Strings de Texto

DONUT PROJECT 2021 - VBA Function:  Convertendo uma Matrix num Vetor - Convert Matrix to a Vector

DONUT PROJECT 2021 - VBA Function:  Como tornar o Formulário Transparente no MS Excel?

DONUT PROJECT 2021 - VBA Function:  Faça Buscas no Google a Partir da Célula do MS Excel - Search Google From a Cell

DONUT PROJECT 2021 - VBA Function:  Decompondo um Nome nas Dimensões de uma Matriz

DONUT PROJECT 2021 - VBA Function: Extraindo o Último Sobrenome de um Nome Completo ou a Última Palavra de uma Frase

DONUT PROJECT 2021 - VBA Function:  Extraindo o Segundo Nome de um Nome Completo ou a Segunda Palavra de uma Frase

DONUT PROJECT 2021 - VBA Function: Extraindo o Primeiro Nome ou  a Primeira Palavra de uma Frase

Série Piece of Cake

Séries Donut

Leia também:

eBook: Série DONUT PROJECT 2015: Projetos e Códigos de Visual Basic for Applications - Autor: André Luiz Bernardes

eBook: Série Top 10 Funções: Top 10 Funções VBA para o Microsoft Excel - Autor: André Luiz Bernardes

eBook: Série Funções Poderosas: 13 Funções Poderosas no MS Excel - Autor: André Luiz Bernardes

eBook: Série Visual Basic For Application: Criando Logs de acesso: Dicas e Códigos de Visual Basic for Applications - Autor: André Luiz Bernardes

eBook: Série VBA Tips: Rastrei seus Dashboards, Scorecards, Reports, Relatórios, Planilhas e Aplicações - Dicas e Códigos - Autor: André Luiz Bernardes

eBook: Série Data Science: Big Data, Como? - Autor: André Luiz Bernardes

eBook: Série Smarter Analytic: 5 Previsões de Big Data - Autor: André Luiz Bernardes


Comente e compartilhe este artigo!

brazilsalesforceeffectiveness@gmail.com
Inline image 1

Nenhum comentário:

Postar um comentário

diHITT - Notícias