Notifications
Clear all

Data Invertida na Importação de arquivo texto

13 Posts
2 Usuários
0 Reactions
1,927 Visualizações
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

Senhores,

Eu estou com o mesmo problema de datas com uma macro, ja tentei de tudo, até as dicas daqui mas mesmo assim o Excel teima em alterar o dia para mes e mes para dia.

Alguem pode me ajudar???

 
Postado : 20/02/2014 7:07 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Digo203, movi e criei um novo tópico pelo fato de ter postado em outro tópico em que o assunto é diferente.

[]s

 
Postado : 20/02/2014 7:59 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Tente trocar na macro

Array(89, 1)

por

Array(89, 4)

Me avise.

Abs,

 
Postado : 20/02/2014 8:32 pm
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

Obrigado Mauro por colocar no lugar correto.

Como no topico anterior estava falando de inversão de datas, eu achei melhor pegar o gancho com a minha duvida. :D

Quanto a ajuda do Mandrix fiz a alteração mencionada e na Coluna I (Data da Transação) surtiu o efeito desejado, porem na coluna B (Data Mov) ainda o Excel teima em inverter as datas mesmo estando na mesma formatação.

Sabem como posso alterar isso???

 
Postado : 21/02/2014 5:21 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Array(0, 1)

por

Array(0, 4)

Me avise.

Abs,

 
Postado : 21/02/2014 5:54 am
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

Bom Dia!

Fiz a alteração mencionada, mas nada ainda.

O Excel ainda esta teimando em inverter as datas.

Abraços,

 
Postado : 21/02/2014 6:55 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

A inversão de data está ocorrendo no momento em que é retirado do campo a sigla "Hora:"

    Selection.Replace What:="hora:", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Motivo: Permanece ainda "anexado" ao campo alguns caracteres espaço; assim o Excel reconhece o conteúdo como data e "tenta" converter, nessa conversão ocorre a inversão, pois o padrão interno do aplicativo e m/d/a.

Altere o trecho conforme abaixo e veja se atende:

    Selection.Replace What:="     hora:", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 
Postado : 21/02/2014 7:18 am
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

A inversão de data está ocorrendo no momento em que é retirado do campo a sigla "Hora:"

    Selection.Replace What:="hora:", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Motivo: Permanece ainda "anexado" ao campo alguns caracteres espaço; assim o Excel reconhece o conteúdo como data e "tenta" converter, nessa conversão ocorre a inversão, pois o padrão interno do aplicativo e m/d/a.

Altere o trecho conforme abaixo e veja se atende:

    Selection.Replace What:="     hora:", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Olá Reinaldo!

O tentei alterar essa parte do codigo que vc mencionou, mas ainda assim o Excel nao me da tregua, continua a inverter dia/mes, eu até tentei forçar dentro do codigo logo abaixo na alteraçao que vc me disse com incluindo esse codigo: Selection.NumberFormat = "dd/mm/yyyy", mas ainda assim nada.

 
Postado : 21/02/2014 8:05 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Experimente assim então:

Sub Macro1()
'
' Macro1 Macro
'
   strArquivo = Application.GetOpenFilename("Arquivos de texto (*.txt),*.txt") '
    Workbooks.OpenText Filename:=strArquivo, Origin:= _
        xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1) _
        , Array(10, 1), Array(21, 1), Array(53, 1), Array(61, 1), Array(71, 1), Array(89, 4), Array( _
        106, 1), Array(126, 1)), TrailingMinusNumbers:=True
        
    nWo = ActiveWorkbook.Name 'Nome do arquivo aberto
    nSh = ActiveSheet.Name 'Nome da planilha no arquivo aberto
        
    Range("A7:H7,A17:H17,A27:H27,A37:H37,A47:H47,A57:H57").Select
    Range("A57").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Range("B1").Select
    ActiveSheet.Paste
    
    Sheets(nSh).Select
    Range("H2,H12,H22,H32,H42,H52,H62").Select
    Range("H62").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Plan1").Select
    Range("A1").Select
    ActiveSheet.Paste
    For x = 1 To 6
        Cells(x, 1).Value = CDate(Format(Left(Cells(x, 1), 10), "dd/mm/yyyy"))
    Next
    'Selection.Replace What:="     hora:", Replacement:="", LookAt:=xlPart, _
    '    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    '    ReplaceFormat:=False
        
    Sheets(nSh).Select
    Range("A2,A12,A22,A32,A42,A52,A62").Select
    Range("A62").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Plan1").Select
    Range("J1").Select
    ActiveSheet.Paste
    Range("H1:H7,A1:A7").Select
    Range("A1").Activate
    Application.CutCopyMode = False
    Selection.NumberFormat = "dd/mm/yyyy"
    Range("A1:J7").Select
    Selection.Copy
    Windows("ARV.xlsm").Activate
    Sheets("Base").Select
    Range("B4").Select
    Selection.Insert Shift:=xlDown
    Range("M1").Select
    Application.CutCopyMode = False
End Sub
 
Postado : 21/02/2014 8:30 am
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

Experimente assim então:

Sub Macro1()
'
' Macro1 Macro
'
   strArquivo = Application.GetOpenFilename("Arquivos de texto (*.txt),*.txt") '
    Workbooks.OpenText Filename:=strArquivo, Origin:= _
        xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1) _
        , Array(10, 1), Array(21, 1), Array(53, 1), Array(61, 1), Array(71, 1), Array(89, 4), Array( _
        106, 1), Array(126, 1)), TrailingMinusNumbers:=True
        
    nWo = ActiveWorkbook.Name 'Nome do arquivo aberto
    nSh = ActiveSheet.Name 'Nome da planilha no arquivo aberto
        
    Range("A7:H7,A17:H17,A27:H27,A37:H37,A47:H47,A57:H57").Select
    Range("A57").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Range("B1").Select
    ActiveSheet.Paste
    
    Sheets(nSh).Select
    Range("H2,H12,H22,H32,H42,H52,H62").Select
    Range("H62").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Plan1").Select
    Range("A1").Select
    ActiveSheet.Paste
    For x = 1 To 6
        Cells(x, 1).Value = CDate(Format(Left(Cells(x, 1), 10), "dd/mm/yyyy"))
    Next
    'Selection.Replace What:="     hora:", Replacement:="", LookAt:=xlPart, _
    '    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    '    ReplaceFormat:=False
        
    Sheets(nSh).Select
    Range("A2,A12,A22,A32,A42,A52,A62").Select
    Range("A62").Activate
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Plan1").Select
    Range("J1").Select
    ActiveSheet.Paste
    Range("H1:H7,A1:A7").Select
    Range("A1").Activate
    Application.CutCopyMode = False
    Selection.NumberFormat = "dd/mm/yyyy"
    Range("A1:J7").Select
    Selection.Copy
    Windows("ARV.xlsm").Activate
    Sheets("Base").Select
    Range("B4").Select
    Selection.Insert Shift:=xlDown
    Range("M1").Select
    Application.CutCopyMode = False
End Sub

Reinaldo,

Deu um pequeno erro (Erro em tempo de execução "13" Tipos Inconpátiveis ) nessa parte:

Cells(x, 1).Value = CDate(Format(Left(Cells(x, 1), 10), "dd/mm/yyyy"))

 
Postado : 21/02/2014 8:46 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Creio então que as datas da range "H2,H12,H22,H32,H42,H52,H62" podem ficar em branco (vazio)

Altere conforme abaixo:

    For x = 1 To 7
        If Cells(x, 1) <> "" Then
            Cells(x, 1).Value = CDate(Format(Left(Cells(x, 1), 10), "dd/mm/yyyy"))
        End If
    Next
 
Postado : 21/02/2014 8:51 am
(@digo203)
Posts: 117
Estimable Member
Topic starter
 

Creio então que as datas da range "H2,H12,H22,H32,H42,H52,H62" podem ficar em branco (vazio)

Altere conforme abaixo:

    For x = 1 To 7
        If Cells(x, 1) <> "" Then
            Cells(x, 1).Value = CDate(Format(Left(Cells(x, 1), 10), "dd/mm/yyyy"))
        End If
    Next

Opa Reinaldo!

Obrigado pela paciencia.

Deu certo.

Agora vou tentar estudar o que vc fez para ver se compreendo.

Obrigado pela ajuda.

 
Postado : 21/02/2014 11:47 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Caso seja necessário reabrir o tópico, o autor poderá enviar uma MP para um dos moderadores solicitando o desbloqueio.

 
Postado : 21/02/2014 11:56 am