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.

.: Vitrine

Carregando artigos...

Views

Mostrando postagens com marcador EntireRow. Mostrar todas as postagens
Mostrando postagens com marcador EntireRow. Mostrar todas as postagens

Excel Tips - 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


Tags: VBA, Excel, deletar, apagar, excluir, row, lines, linha, range, rows, blank, removing, EntireRow, automatically, delete

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



Sim pessoal. sempre perguntam como deletar linhas em branco da planilha, assim que 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

Tags: VBA, Excel, deletar, apagar, excluir, rows, blank, lines, linha, range, removing, EntireRow, automatically, delete





VBA Excel - Colorindo toda uma linha a partir de um parâmetro numa coluna - Color Entirerow based on a column's value

Blog Office VBA | Blog Excel | Blog Access |
Inline image 2

Depois de termos preenchido uma certa área com resultados processados, ou termos conectado nossa planilha em uma base de dados, podemos propiciar que esta área seja destaca pela aplicação da funcionalidade abaixo.

A partir de um parâmetro qualquer (neste caso na coluna P), podemos definir o destaque de toda uma Linha.



Private Sub Worksheet_Change(ByVal Target As Range)
'Error Handling
On Error Resume Next
    'Check only, if the change happens in Column P.
    If Left(Target.Address(0, 0), 1) = "P" Then
        'Check if selected value changed to Active
        If UCase(Target.Value) = "ACTIVE" Then
            'If Active is selected in drop down list,
            'Row color will change to green.
            Target.EntireRow.Font.Color = RGB(0, 102, 0)
            
        'Check if selected value changed to Deactive
        ElseIf UCase(Target.Value) = "DEACTIVE" Then
            'If Deactive is selected in drop down list,
            'Row color will change to red.
            Target.EntireRow.Font.Color = vbRed
            
        'Check if it's something else than Active or Deactive
        '(Not possible but have been put for validation sake.
        Else
            Target.EntireRow.Font.Color = vbBlack
        End If
    End If
'Turn off Error Handling
On Error GoTo 0
End Sub

Reference:
Tags: VBA, Excel, entirerow, color, column, value, Data Validation, Event Macro, Queries and Solutions


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.




diHITT - Notícias