Ir para conteúdo
Fórum Script Brasil
  • 0

Função de dias corridos sem os feriados


Rafa23_ms

Pergunta

Bom dia, 

estou tentando fazer uma function que pega como parâmetro duas datas e retorna os dias uteis desse período, entretanto não consigo entender o que estou fazendo de errado

'retorna os dias uteis
Public Function DiasUteis(ByVal data_inicial As Date, ByVal data_final As Date) As Integer

    Ano_inicial = Year(data_inicial)
    Ano_final = Year(data_final)
    Aux = 0
    Corridos = WorksheetFunction.NetworkDays(data_inicial, data_final)
    Feriados = 0
    While Aux <= Ano_final
        If Aux = 0 Then
            Aux = Ano_inicial
        End If
        pascoa = WorksheetFunction.Floor(Day(Minute(Aux / 38) / 2 + 56) & "/5" & "/" & Aux, 7) - 34
        pascoa = CDate(pascoa)
        Carnaval1 = CDate(pascoa - 48)
        Calnaval2 = CDate(canaval1 + 1)
        Paixao = CDate(pascoa - 2)
        Corpo = CDate(pascoa + 60)
        tiradentes = WorksheetFunction.Date(Aux, 4, 21)
        confraternizacao = WorksheetFunction.Date(Aux, 1, 1)
        Trabalho = WorksheetFunction.Date(Aux, 5, 1)
        Independencia = WorksheetFunction.Date(Aux, 9, 7)
        Senhora = WorksheetFunction.Date(Aux, 10, 12)
        Finados = WorksheetFunction.Date(Aux, 11, 2)
        proclamacao = WorksheetFunction.Date(Aux, 11, 15)
        Natal = WorksheetFunction.Date(Aux, 12, 25)
        If pascoa > data_inicial Then
            If pascoa < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If pascoa > data_inicial Then
            If pascoa < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Carnaval1 > data_inicial Then
            If Carnaval1 < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Carnaval2 > data_inicial Then
            If Carnaval2 < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Paixao > data_inicial Then
            If Paixao < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Corpo > data_inicial Then
            If Corpo < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If tiradentes > data_inicial Then
            If tiradentes < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If confraternizacao > data_inicial Then
            If confraternizacao < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Trabalho > data_inicial Then
            If Trabalho < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Independencia > data_inicial Then
            If Independencia < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Senhora > data_inicial Then
            If Senhora < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Natal > data_inicial Then
            If Natal < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If Finados > data_inicial Then
            If Finados < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        If proclamacao > data_inicial Then
            If proclamacao < data_final Then
                Feriados = Feriados + 1
            End If
        End If
        Aux = Aux + 1
    Wend
   
    Corridos = Corridos - Feriados
    DiasUteis = Corridos
 End Function

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...