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.
#46330
Boa tarde Senhores.

Apliquei uma macro para que seja deletada as linhas em que for encontrado um valor cadastrado. No meu caso chamo-as de "contas" que são a identificação numérica de minhas contas.

Essas conta estão em linhas que são importadas, então se as linhas tiverem essas contas a macro deve apagar a linha, pois quero limpar o arquivo.

Assim, preciso "cadastrar" essas contas na macro que ao importar eu inicio essa macro para fazer a limpeza.

Até aí tudo bem, a macro funciona se eu programar uma condição para cada conta, mas gostaria de poupar meu tempo em programar e apenas inserir as contas em um array, se é que tem como.

Alguém sabe como poderia fazer isso de forma mais prática?

abaixo minha macro:
Código: Selecionar todos
Sub deletar_contas()


Application.ScreenUpdating = False


Dim i As Long

Dim UltimaLinha As Long

Dim conta As String

i = 2

UltimaLinha = Sheets("Plan1").Cells(Cells.Rows.Count, 2).End(xlUp).Row
    
If UltimaLinha < 2 Then UltimaLinha = 2

        
Nome1 = ThisWorkbook.Worksheets("Plan1").Range("B" & i).Value
          
          
    ' conta = Array(603,9014,610,632)
     
     
        
    For i = 2 To UltimaLinha
    
    
   If Range("B" & i).Value = conta Then
   
   ThisWorkbook.Worksheets("Plan1").Range("B" & i).Delete
   
   
  
   
   'If Range("B" & i).Value = "610" Then
   'If Range("B" & i).Value = "632" Then
   'If Range("B" & i).Value = "649" Then
   'If Range("B" & i).Value = "655" Then
   'If Range("B" & i).Value = "623" Then
   'If Range("B" & i).Value = "661" Then
   'If Range("B" & i).Value = "624" Then
   'If Range("B" & i).Value = "621" Then
   'If Range("B" & i).Value = "622" Then
   'If Range("B" & i).Value = "619" Then
   'If Range("B" & i).Value = "620" Then
   'If Range("B" & i).Value = "627" Then
   'If Range("B" & i).Value = "684" Then
   'If Range("B" & i).Value = "9004" Then
   'If Range("B" & i).Value = "10067" Then
   'If Range("B" & i).Value = "10068" Then
   'If Range("B" & i).Value = "10069" Then
   'If Range("B" & i).Value = "10070" Then
   'If Range("B" & i).Value = "10071" Then
   'If Range("B" & i).Value = "10072" Then
   'If Range("B" & i).Value = "12193" Then
   'If Range("B" & i).Value = "2571" Then
   'If Range("B" & i).Value = "2588" Then
   'If Range("B" & i).Value = "2619" Then
   'If Range("B" & i).Value = "2677" Then
   'If Range("B" & i).Value = "2683" Then
  ' If Range("B" & i).Value = "2708" Then
   'If Range("B" & i).Value = "2737" Then
   'If Range("B" & i).Value = "2750" Then
   'If Range("B" & i).Value = "9002" Then
   'If Range("B" & i).Value = "9151" Then
   'If Range("B" & i).Value = "2980" Then
   'If Range("B" & i).Value = "2996" Then
   'If Range("B" & i).Value = "3004" Then
   'If Range("B" & i).Value = "3369" Then
   'If Range("B" & i).Value = "3375" Then
   'If Range("B" & i).Value = "3317" Then
   'If Range("B" & i).Value = "11744" Then
  ' If Range("B" & i).Value = "11745" Then
   'If Range("B" & i).Value = "11746" Then
   'If Range("B" & i).Value = "11747" Then
   'If Range("B" & i).Value = "11748" Then
   'If Range("B" & i).Value = "11835" Then
  ' If Range("B" & i).Value = "11836" Then
   'If Range("B" & i).Value = "11837" Then
   'If Range("B" & i).Value = "11838" Then
   'If Range("B" & i).Value = "7321" Then
   'If Range("B" & i).Value = "7344" Then
   'If Range("B" & i).Value = "7380" Then
  ' If Range("B" & i).Value = "9136" Then
   'If Range("B" & i).Value = "11749" Then
   'If Range("B" & i).Value = "11750" Then
   'If Range("B" & i).Value = "11829" Then
   'If Range("B" & i).Value = "11830" Then
  ' If Range("B" & i).Value = "11831" Then
   'If Range("B" & i).Value = "11840" Then
   'If Range("B" & i).Value = "9104" Then
   'If Range("B" & i).Value = "11751" Then
  ' If Range("B" & i).Value = "11752" Then
   'If Range("B" & i).Value = "11832" Then
   'If Range("B" & i).Value = "11833" Then
   'If Range("B" & i).Value = "11834" Then
   'If Range("B" & i).Value = "11839" Then
   'If Range("B" & i).Value = "7404" Then
   'If Range("B" & i).Value = "9138" Then
   'If Range("B" & i).Value = "7433" Then
   'If Range("B" & i).Value = "11753" Then
   'If Range("B" & i).Value = "7456" Then
   'If Range("B" & i).Value = "9129" Then
   'If Range("B" & i).Value = "7545" Then
   'If Range("B" & i).Value = "7568" Then
   'If Range("B" & i).Value = "7701" Then
   'If Range("B" & i).Value = "7717" Then
   'If Range("B" & i).Value = "7723" Then
   'If Range("B" & i).Value = "7730" Then
   'If Range("B" & i).Value = "5397" Then
   'If Range("B" & i).Value = "9000" Then
   'If Range("B" & i).Value = "7835" Then
   'If Range("B" & i).Value = "7841" Then
   'If Range("B" & i).Value = "9036" Then
   'If Range("B" & i).Value = "5751" Then
   'If Range("B" & i).Value = "5752" Then
   'If Range("B" & i).Value = "5749" Then
   'If Range("B" & i).Value = "5965" Then
   'If Range("B" & i).Value = "5966" Then
   'If Range("B" & i).Value = "5963" Then
   'If Range("B" & i).Value = "5964" Then
   'If Range("B" & i).Value = "4714" Then
   'If Range("B" & i).Value = "5351" Then
   'If Range("B" & i).Value = "5368" Then
              
           
            'ThisWorkbook.Worksheets("Plan1").Range("B" & i).Delete
           

End If

             
        
    Next
    
MsgBox "Contas contábeis fiscais deletadas", vbInformation, " Deletar contas"

Application.ScreenUpdating = True


End Sub















Você não está autorizado a ver ou baixar esse anexo.
Editado pela última vez por Pegorini em 02 Ago 2019 às 07:32, em um total de 1 vez.
#46340
Consegui bolar um script rapidinho...
Código: Selecionar todos
Sub deletar_contas()

Dim UltimaLinha As Long
Dim conta As Variant
Dim valor As String
Dim i As Integer

UltimaLinha = Sheets("Plan1").Cells(Cells.Rows.Count, 2).End(xlUp).Row
    
If UltimaLinha < 2 Then UltimaLinha = 2
    
          
    conta = Array(603, 9014, 610, 632)
        
    i = 2
    
    While i <= UltimaLinha
        For j = 0 To UBound(conta)
            valor = ThisWorkbook.Worksheets("Plan1").Range("B" & i).Value
            If StrComp(valor, conta(j), vbTextCompare) = 0 Then
                
                'Esta na string
                ThisWorkbook.Worksheets("Plan1").Range("B" & i).Delete
                UltimaLinha = UltimaLinha - 1
                i = i - 1
                Exit For
            End If
        Next
        i = i + 1
    Wend
    
    MsgBox "Deletado!", vbInformation

End Sub
             
      
Só resta digitar os valores na array
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