Propósito

✔ Programação GLOBAL® - Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog devem ser tratados como consultoria freelance. Queiram contatar-nos: brazilsalesforceeffectiveness@gmail.com | ESTE BLOG NÃO SE RESPONSABILIZA POR QUAISQUER DANOS PROVENIENTES DO USO DOS CÓDIGOS AQUI POSTADOS EM APLICAÇÕES PESSOAIS OU DE TERCEIROS.

VBA Excel - Deletando Colunas ou Linhas no Range - Delete Columns or Lines in the range



Caros,
Continuando na linha: "Revisitando As primeiras funções que desenvolvi".




DICA: Todas as funções que criarmos que tenham interação física direta nas planilhas que estivermos utilizando, terão uma performance muito melhor se colocarmos o comando Application.ScreenUpdating = False, antes do início do respectivo processamento.



Como deletar as linhascolunas num range informado?





Sub DelEveryNthR (DeleteRange As Range, N As Integer)



    Dim rCount As Long, r As Long







    Application.ScreenUpdating = False




    If DeleteRange Is Nothing Then Exit Sub



    If DeleteRange.Areas.Count > 1 Then Exit Sub



    If N < 2 Then Exit Sub







    With DeleteRange



        Let rCount = .Rows.Count







        For r = N To rCount Step N - 1



            .Rows(r).EntireRow.Delete



        Next r



    End With



End Sub







Sub DeleteEveryNthC (DeleteRange As Range, N As Integer)



    Dim cCount As Long, c As Long




    Application.ScreenUpdating = False




    If DeleteRange Is Nothing Then Exit Sub



    If DeleteRange.Areas.Count > 1 Then Exit Sub



    If N < 2 Then Exit Sub







    With DeleteRange



        Let cCount = .Columns.Count







        For c = N To cCount Step N - 1



            .Columns(c).EntireColumn.Delete



        Next c



    End With



End Sub




TagsBernardes, MS, Microsoft, Office, Excel, deletar, apagar, excluir, row, lines, linha, range, rows, blank, removing, EntireRow, automatically, delete, column, coluna



André Luiz Bernardes
A&A® - Work smart, not hard.




VBA Excel - Deletando Colunas vazias no Range - Delete Columns selected in the range


Caros,
Continuando na linha: "Revisitando As primeiras funções que desenvolvi".

Como deletar as colunas que estão vazias num range informado?


Sub DelEmptyC (DeleteRange As Range)


' Deleta todas as colunas no Range





Dim cCount As Integer, c As Integer





    If DeleteRange Is Nothing Then Exit Sub


    If DeleteRange.Areas.Count > 1 Then Exit Sub





    With DeleteRange


        Let cCount = .Columns.Count





        For c = cCount To 1 Step -1


            If Application.CountA(.Columns(c)) = 0 Then 


                .Columns(c).EntireColumn.Delete


            End If


        Next c


    End With


End Sub


Tags: Bernardes, MS, Microsoft, Office, Excel, deletar, apagar, excluir, column, colunas, range















André Luiz Bernardes
A&A® - Work smart, not hard in any place.
Skype: inanyplace 

VBA Excel - Deletando Linhas vazias no Range - Delete Rows selected in the range

Caros,
Continuando na linha: "Revisitando As primeiras funções que desenvolvi".

Como deletar as linhas que estão vazias num range informado?

Function DelEmptyR(DeleteRange As Range)
' Deleta todas as linhas vazias no Range
' informa o range que a função analisará.

Dim rCount As Long, r As Long

    If DeleteRange Is Nothing Then Exit Sub

    If DeleteRange.Areas.Count > 1 Then Exit Sub

    With DeleteRange
        Let rCount = .Rows.Count

        For r = rCount To 1 Step -1
            If Application.CountA(.Rows(r)) = 0 Then 
                .Rows(r).EntireRow.Delete
            End If
        Next r
    End With
End Function




Tags: Bernardes, MS, Microsoft, Office, Excel, deletar, apagar, excluir, row, lines, linha, range, row


André Luiz Bernardes
A&A® - Work smart, not hard.




VBA Excel - Excluindo linhas em branco ao abrir a Planilha - Removing Blank Rows Automatically


Olá pessoal!

Alguns perguntaram como fazer para deletar as linhas que estão em branco na planilha, logo que a esta for aberta.

Segue um código, simples, honesto, rápido e limpinho.

Private Sub Worksheet_Change (ByVal Target As Range)
'Deleta todas as linhas que estiverem em branco que existirem.  
'Previne loops infinitos Let Application.EnableEvents = False  
'Caso haja mais de uma célula selecionada.

If Target.Cells.Count > 1 Then
GoTo SelectionCode  
If WorksheetFunction.CountA(Target.EntireRow) = 0 Then
Target.EntireRow.Delete
End If  

Let Application.EnableEvents = True  
Exit Sub

SelectionCode:
If WorksheetFunction.CountA(Selection.EntireRow) = 0 Then
Selection.EntireRow.Delete
End If  

Let Application.EnableEvents = True
End Sub

TagsBernardes, MS, Microsoft, Office, Excel, deletar, apagar, excluir, row, lines, linha, range, rows, blank, removing, EntireRow, automatically, delete



André Luiz Bernardes
A&A® - Work smart, not hard.





diHITT - Notícias