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
  • Avatar do usuário
Por efs2016
Posts
#16244
Galera, estou fazendo este controle de atendimento para o meu trabalho. Eu não sou muito bom com VBA. Toda vez que clico no botão "Relatórios", gera o relatório, porém, além de ignorar as datas entre digitadas nos campos da Data, o relatório sai com um dia a mais e quatro a mais. Por exemplo: Se eu digitar 01/10/2016 a 15/10/2016, sai no relatório 02/10/2020 a 16/10/2020.
Está adicionado um dia e quatro anos. Alguém poderia me ajudar?
Existe duas Abas da planilha ocultas.
Segue anexo modelo.
Muito obrigado!! :?:
Por efs2016
Posts
#16245
Desculpe. Falta este código no VBA.

Private Sub bt_gerar_Click()
desproteger

'puxando as datas
If datainicial = "" Or datafinal = "" Then Exit Sub

Do Until Plan5.Cells(lin, 1) = ""
If Plan5.Cells(lin, 2) >= CDate(datainicial) And _
Plan5.Cells(lin, 2) <= CDate(datafinal) Then
Plan5.Cells(linha, 2) = CDate(Plan5.Cells(lin, 2))
Sheets("Base").Cells(linha, 15) = Sheets("Base").Cells(lin, 2)
Sheets("Base").Cells(linha, 16) = Sheets("Base").Cells(lin, 3)
Sheets("Base").Cells(linha, 17) = Sheets("Base").Cells(lin, 9)
Sheets("Base").Cells(linha, 18) = Sheets("Base").Cells(lin, 10)
linha = linha + 1
End If
lin = lin + 1
Loop
MsgBox "Processo concluído - " & datainicial & " à " & datafinal

'xxxxxxxxxxxxx
Avatar do usuário
Por Reinaldo
Avatar
#16261
Não consegui verificar na rotina/explanação nada que justifique a ocorrencia.
Uma possibilidade, a planilha que está utilizando está no sistema de dada 1904.
Para verificar va no menu superior, em "Arquivo", selecione "Opções" , depois 'Avançado" na tela ao lado "navegue" até
-->Ao Calcular esta pasta de trabalho <--, verifique se a opção Usar sistema de data... está selecionada.
Avatar do usuário
Por alexandrevba
Avatar
#16422
Bom dia!!


Veja se ajuda.
Faça as adaptações necessárias!!
Código: Selecionar todos
Dim LR As Long
Dim sh As Worksheet
Dim startDate As Date
Dim endDate As Date

If txtStartDate = "" Or txtEndDate = "" Then Exit Sub
startDate = datafinal.Value
endDate = datafinal.Value
                                                   
Set sh = Sheets("Base")
    With sh
        LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        .Range("A9:L9").AutoFilter
        .Range("A9:J" & LR).AutoFilter Field:=10, Criteria1:=comboatendente.Value
        .Range("A9:J" & LR).AutoFilter Field:=2, Criteria1:=">=" & Format(startDate, "yyyy-mm-dd"), Operator:=xlAnd, Criteria2:="<=" & Format(endDate, "yyyy-mm-dd")
    End With
    
    sh.Range("A10", sh.Range("J56000").End(xlUp)).SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Rel").Range("A1").End(xlUp).Offset(1)
    If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Att
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