Notifications
Clear all

Macro para deletar aba de acordo com critério

6 Posts
4 Usuários
0 Reactions
1,250 Visualizações
(@retsteo)
Posts: 7
Active Member
Topic starter
 

Boa tarde, necessito de uma ajuda, tenho uma macro para deletar determinadas colunas, porém depende do numero de colunas que possui cada documento eu tenho que alterar a macro, gostaria de ajuda para uma macro que deleta-se as abas pulando uma, Ex.: deletar Table 1, Table 3, Table 5, Table 7...

Esta é macro que uso:

Sub Deletar_Aba()

Application.DisplayAlerts = False

Sheets("Table 1").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 3").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 5").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 7").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 9").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 11").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 13").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 15").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 17").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 19").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 21").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 23").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 25").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 27").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 29").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 31").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 33").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 35").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 37").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 39").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 41").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 43").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 45").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 47").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 49").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 51").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 53").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 55").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 57").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 59").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 61").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 63").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 65").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 67").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 69").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 71").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 73").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 75").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 77").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 79").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 81").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 83").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 85").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 87").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 89").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 91").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 93").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 95").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 97").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 99").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 101").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 103").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 105").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 107").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 109").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 111").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 113").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 115").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 117").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 119").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 121").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 123").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 125").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 127").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 129").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 131").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 133").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 135").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 137").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 139").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 141").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 143").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 145").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 147").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 149").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 151").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 153").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 155").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 157").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 159").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 161").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 163").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 165").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 167").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 169").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 171").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 173").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 175").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 177").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 179").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 181").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 183").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 185").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 187").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 189").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 191").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 193").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 195").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 197").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 199").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 201").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 203").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 205").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 207").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 209").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 211").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 213").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 215").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 217").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 219").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 221").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 223").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 225").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 227").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 229").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 231").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 233").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 235").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 237").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 239").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 241").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 243").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 245").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 247").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 249").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 251").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 253").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 255").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 257").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 259").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 261").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 263").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 265").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 267").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 269").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 271").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 273").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 275").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 277").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 279").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 281").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 283").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 285").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 287").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 289").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 291").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 293").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 295").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 297").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 299").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 301").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 303").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 305").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 307").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 309").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 311").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 313").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 315").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 317").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 319").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 321").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 323").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 325").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 327").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 329").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 331").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 333").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 335").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 337").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 339").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 341").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 343").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 345").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 347").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 349").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 351").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 353").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 355").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 357").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 359").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 361").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 363").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Table 365").Select
ActiveWindow.SelectedSheets.Delete




Application.DisplayAlerts = True

call COPIAR

End sub
 
Postado : 31/03/2017 11:50 am
Wagner Morel
(@wagner-morel-vidal-nobre)
Posts: 0
Illustrious Member
 

Retsteo,

Boa tarde!

Não entendi... qual é critério para deletar a aba???

Desenvolvo pequenas soluções em VBA Excel a valores que variam entre R$ 50,00 a R$ 200,00. Se te interessar, entre no meu instagran (vba_excel_desenvolvimento)

Atenciosamente
Wagner Morel

 
Postado : 31/03/2017 12:05 pm
(@retsteo)
Posts: 7
Active Member
Topic starter
 

Wagner,

Boa tarde!

O critério é as abas impares que eu tenho que deletar. Table 1, Table 3, Table 5...

 
Postado : 31/03/2017 12:51 pm
brunoxro
(@brunoxro)
Posts: 698
Honorable Member
 

Boa noite Retsteo,

Teste o código que está no módulo1 do arquivo em anexo.

O código vai deletar as planilhas ímpares e que tenha um espaço, como no seu código: Table 1, Table 3, Table 5...

Teste e dê retorno.

att,

 
Postado : 01/04/2017 8:30 pm
(@osvaldomp)
Posts: 858
Prominent Member
 

critério para deletar - planilhas nas posições (índice) ímpar ---> 1, 3, 5, ..., 97, ..., 365, ...
funciona se as guias estiverem ordenadas ---> Table 1, Table 2, Table 3, ...

Sub ExcluiPlansEmPosiçõesÍmpares()
 Dim i As Integer, k As Long, m As Long, Plans() As Variant
  k = IIf(ThisWorkbook.Sheets.Count Mod 2 = 1, ThisWorkbook.Sheets.Count, ThisWorkbook.Sheets.Count - 1)
   For i = 1 To k Step 2
     ReDim Preserve Plans(m): Plans(m) = Sheets(i).Name: m = m + 1
   Next i
   Application.DisplayAlerts = False
    Worksheets(Plans).Delete
   Application.DisplayAlerts = True
End Sub

critério para deletar - planilhas cujos nomes terminem com número ímpar ---> Table 1, Table 3, Table 5, ..., Table 97, ..., Table 365, ...

Sub ExcluiPlansComÍmparNoNome()
 Dim ws As Worksheet
  Application.DisplayAlerts = False
   For Each ws In ThisWorkbook.Sheets
    If Right(ws.Name, Len(ws.Name) - 6) Mod 2 = 1 Then ws.Delete
   Next ws
  Application.DisplayAlerts = True
End Sub

Osvaldo

 
Postado : 02/04/2017 2:47 pm
(@retsteo)
Posts: 7
Active Member
Topic starter
 

Funcionou, Muito Obrigado Bruno e Osvaldo!

 
Postado : 03/04/2017 7:54 am