rafael.cadina
New Member
- Joined
- Aug 30, 2011
- Messages
- 4
I'm a beginneer as a Excel VBA developer, but i'm trying to automate some sheets i have in order to save time.
I wrote a code that works like a charm when i keep pressing F8 (step-by-step) but when i run it fully nothing happens. I don't know if it's because it's too fast that my sub can't copy-paste the things i need.
Just below is my code. Does anybody know what is happening? Why is it not working when i press the "play" button straight? Thanks in advance!
Same happen with the mini sub called Excluir_Linhas_Em_Branco that is useful for clearing blank rows.
I wrote a code that works like a charm when i keep pressing F8 (step-by-step) but when i run it fully nothing happens. I don't know if it's because it's too fast that my sub can't copy-paste the things i need.
Just below is my code. Does anybody know what is happening? Why is it not working when i press the "play" button straight? Thanks in advance!
Same happen with the mini sub called Excluir_Linhas_Em_Branco that is useful for clearing blank rows.
Code:
Sub Criar_Aba_Consolidada() 'Cria aba consolidada
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Consolidada"
End Sub
Sub Agregar() 'Agrega as macros criadas
Criar_Aba_Consolidada
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> "m-cs" Or sht.Name <> "setup" Or sht.Name <> "Consolidada" Then
sht.Select
Excluir_Colunas_Nao_Uteis
Excluir_Linhas_Em_Branco
Copiar_Para_Consolidada
End If
Next sht
End Sub
Sub Excluir_Colunas_Nao_Uteis() 'Exclui colunas não utilizadas na DBCS
Cells.Copy
Cells.PasteSpecial Paste:=xlPasteValues
Cells.PasteSpecial Paste:=xlPasteFormats
Range("B:C,G:H,J:O").Delete Shift:=xlToLeft
End Sub
Sub Excluir_Linhas_Em_Branco() 'Exclui todas as linhas em branco
Coluna_Base = "B"
For i = 1 To 3
Linha_Final = Cells(Rows.Count, Coluna_Base).End(xlUp).Row
Dim rng As Range
Set rng = Range(Coluna_Base & "2:" & Coluna_Base & Linha_Final)
For Each c In rng.Cells
If IsEmpty(c) = True Then
c.EntireRow.Delete
End If
Next c
Next i
End Sub
Sub Copiar_Para_Consolidada()
Cells.Copy
Sheets("Consolidada").Select
Linha_Final = Cells(Rows.Count, "B").End(xlUp).Row
Range("A" & Linha_Final + 1).Select
Cells.PasteSpecial Paste:=xlPasteValues
Cells.PasteSpecial Paste:=xlPasteFormats
End Sub
Last edited: