Notifications
Clear all

Substituir valor se for igual

3 Posts
2 Usuários
0 Reactions
728 Visualizações
(@hyonxd)
Posts: 0
New Member
Topic starter
 

Olá galera, tudo beleza?

Estou com um problema, em relação a uma exportação que consegui fazer.

Um aquivo em txt que eu tenho, toda vez que o conteúdo é exportado para o excel, como padrão deve-se armazenar abaixo do resultado anterior.
o que eu quero fazer é que quando o resultado for igual o anterior ele somente substituir em vez de colar embaixo. isso é possivel ?

Este é meu codigo:

Sub Macro_Historico_Linha()


    Sheets("Base de dados").Select
    Range("A1").Select
Dim fName As String, LastRow As Long

'fName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If fName = "False" Then Exit Sub

LastRow = Range("A" & Rows.Count).End(xlUp).Row + 1
    With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & "D:Meus Documentoschubaca.txt", _
        Destination:=Range("A" & LastRow))
        .Name = "sample"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, _
               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
    End With
    Sheets("Resultado").Select
    Range("A1").Select
End Sub
 
Postado : 27/10/2016 10:42 am
(@djunqueira)
Posts: 0
New Member
 

Se vc tiver a versão 2013 ou 2016 do Excel é possível fazer isso com Nova Consulta.
Bem fácil diga-se de passagem, mas p/ isso anexe sua planilha.

 
Postado : 27/10/2016 4:47 pm
(@hyonxd)
Posts: 0
New Member
Topic starter
 

Meu excel é 2010.

Estava tentando fazer algo do tipo declarar uma variavel e dar a ela o valor da coluna, e caso o valor seja igual ela substituísse mas não da certo por aqui

 
Postado : 28/10/2016 8:46 am