Issues when running a sub

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.

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:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top