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
#38160
Olá. Eu estou usando esse código para abrir um arquivo txt, PARTE1, o qual irá receber valores repetidos que se encontram numa planilha, a Plan5. Nessa planilha não posso excluir os duplicados.
O que preciso é fazer com que os valores repetidos sejam excluídos no arquivo txt e só fiquem nele os exclusivos. Qualquer ajuda é bem vinda
Código: Selecionar todos
Sub PTE1()
   Workbooks("LISTA.xlsm").Sheets("Plan5").activate 
 Ulinha =cells(Rows.Count, 27).end(xlUp).row
Open "C:\Users\Contabilidade\Documents\Loja\PARTE1. txt" for output as 1
         For m=2 to Ulinha 
                 Print #1,cells(m, 27)
         Next
   Open 1 
End sub 
#38161
Sem testar, mas experimente:
Código: Selecionar todos
Sub PTE1()
Workbooks("LISTA.xlsm").Sheets("Plan5").Activate
Ulinha = Cells(Rows.count, 27).End(xlUp).Row
Open "C:\Users\Contabilidade\Documents\Loja\PARTE1. txt" For Output As 1
    For m = 2 To Ulinha
        If Application.WorksheetFunction.CountIf(Range(Cells(2, 27) & ":" & Cells(m, 27)), Cells(m, 27)) = 1 Then Print #1, Cells(m, 27)
    Next
Close #1
End Sub
#38232
Olá Reinaldo. Estou adaptando sua solução para minha necessidade, estou tentando excluir duplicados com o código abaixo, mas o resultado é:
0111
7777
7777
Veja que tem um valor respetido.
No momento não consigo anexar uma planilha de exemplo. Na planilha a situação é a seguinte(desconsidere as palavras CEM e JC, são apenas codigos, o loop não inclui essas palavras) :
BH2: O111
BH3:CEM
BH4:JC
BH5:JC
BI2:-
BI3:-
BI4:CEM
BI5:JC
BJ2: -
BJ3: -
BJ4: 7777
BK2: -
BK3: -
BK4: 7777
BK5: 7777

Código: Selecionar todos
Sub PTE1()
Workbooks("LISTA.xlsm").Sheets("Plan5").Activate
Open "C:\Users\Contabilidade\Documents\Loja\PARTE1.txt" For Output As 1
        If Range("BH2") <> "-" Then Print #1, Range("BH2")
    For m = 2 To 3         ' Coluna BI
       If Cells(m, 61) <> "-" And Application.WorksheetFunction.CountIf(Range("BI2:BI" & m), Range("BI" & m)) = 1 Then Print #1, Cells(m, 61)
    Next m
    For n = 2 To 4         ' Coluna  BJ
       If Cells(n, 62) <> "-" And Application.WorksheetFunction.CountIf(Range("BJ2:BJ" & n), Range("BJ" & n)) = 1 Then Print #1, Cells(n, 62)
    Next n
    For o = 2 To 5         ' Coluna  BK
       If Cells(o, 63) <> "-" And Application.WorksheetFunction.CountIf(Range("BK2:BK" & o), Range("BK" & o)) = 1 Then Print #1, Cells(o, 63)
    Next o
Close #1
End Sub
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