Notifications
Clear all

Excluir linhas em branco

9 Posts
3 Usuários
0 Reactions
1,565 Visualizações
(@robertonl)
Posts: 0
New Member
Topic starter
 

Boa tarde.
Tenho um pequeno problema de adaptação de codigo de exclusão de linhas em branco.
Adaptei uma macro para deletar toda linha que estiver com uma célula em branco, ou seja, no intervalo de "A3:G"& ulinha, independente em qual celula estiver com o campo vazio, toda a linha estará sendo excluida.
O que está acontecendo é que quando roda a macro os valores sobem para a celula em branco.
O comando que exclui toda a coluna no intervalo de "a:G" independente qual célula esteja com valor em branco é este

Lançamentos.Range("A3:g" & ulinha).SpecialCells(xlCellTypeBlanks).Delete

Sub Atualiza_lançamentos()

' Atualiza_Lançamentos Macro
' Atualiza Lançamento de Entradas e Saidas de Material de Embalagem
' Gravado por Denilson Roberto de Souza

Dim w As Worksheet
Dim senha As String
senha = "acerf15"
Set w = Lançamentos
Dim ulinha As Long
Dim Linha As String
Dim LR As Long
w.Activate
On Error Resume Next
    If w.ProtectContents = True Then
    
        w.Unprotect senha
    
    End If

ulinha = w.Cells(Cells.Rows.Count, 1).End(3).Row
On Error Resume Next
    For I = 3 To ulinha
    
        w.Cells(I, "F") = w.Cells(I, "B") & " " & w.Cells(I, "D")
        
    Next I
  
Range("e3").Select
ActiveCell.Formula = "=iferroR(vlookup(D3,cadastro!A:B,2,0),""PRODUTO NÃO CADASTRADO"")"
Range("d3").Select
Selection.End(xlDown).Select
lin = ActiveCell.Row
rg = "e3:e" & lin
ActiveCell.Value = ActiveCell.Value
Range("e3").Select
'i = 1
Selection.AutoFill Destination:=Range(rg), Type:=xlFillDefault
Range("e3:e" & lin).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  :=False, Transpose:=False
Application.CutCopyMode = False

cont = 3
Do Until IsEmpty(Cells(cont, 2))
   If IsError(Cells(cont, 2)) Then
       Cells(cont, 2) = " "
   End If
cont = cont + 1
Loop
'Lançamentos.Range("A3:g" & ulinha).SpecialCells(xlCelllinBlanks).Delete '.shift (xlUp)
Lançamentos.Range("A3:g" & ulinha).SpecialCells(xlCellTypeBlanks).Delete
Linha = Sheets("Lançamentos").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row



w.Protect senha

End Sub
 
Postado : 17/04/2018 12:14 pm
(@leandroxtr)
Posts: 0
New Member
 

Boa tarde!

Acredito que este tópico irá ajudá-lo:

link: http://www.minhasplanilhas.com.br/delet ... zia-excel/

Abraços!

 
Postado : 17/04/2018 1:09 pm
(@robertonl)
Posts: 0
New Member
Topic starter
 

Ainda não resolveu

 
Postado : 18/04/2018 10:14 am
(@robertonl)
Posts: 0
New Member
Topic starter
 

Boa tarde.
Criei esta macro, que substitui células vazias por letra e depois exclui toda linha, porem estou tentando adapta-la para iniciar e até a ultima linha que contém informação e deletar.
se alguém possuir ideia melhor, aceito sugestão.

Sub Testando_Macro()
'
' Testando_Macro Macro
'

'
Range("A3:g70").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("A3:G12").Select
    Selection.Replace what:="", Replacement:="x", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
Range("a3").Select
Cells.Find(what:="X").Activate
lin = ActiveCell.Row
Rows(lin).Select
Selection.Delete shift:=xlDown

End Sub
 
Postado : 18/04/2018 11:30 am
(@klarc28)
Posts: 0
New Member
(@robertonl)
Posts: 0
New Member
Topic starter
 

Criei uma macro, na qual qualquer célula vazia entre ("a:e") e a coluna g que estiverem serão substituída pela letra x e depois estas mesma linha serão totalmente excluídas.
Porém ela está retornando a um erro, que realizei algumas tentativas, porém sem sucesso.

 
Postado : 22/04/2018 8:01 pm
(@klarc28)
Posts: 0
New Member
 
Sub excluir()


Dim linha As Long
Dim coluna As Long
inicio:

For linha = 2 To Planilha1.UsedRange.Rows.Count
For coluna = 1 To 5
If Planilha1.Cells(linha, coluna).Value = "" Then
Planilha1.Cells(linha, coluna).EntireRow.Delete
GoTo inicio
End If
Next coluna
Next linha


For linha = 2 To Planilha1.UsedRange.Rows.Count
If Planilha1.Range("G" & linha).Value = "" Then
Planilha1.Range("A" & linha).EntireRow.Delete
GoTo inicio
End If
Next linha
End Sub
 
Postado : 22/04/2018 8:18 pm
(@robertonl)
Posts: 0
New Member
Topic starter
 

Fiz uma adaptação desta macro que funcionou perfeitamente, porém em uma guia que a célula e e f estão protegidas por senha e a coluna f está oculta ela ficou lenta, demorando a excluir

 
Postado : 25/04/2018 7:43 pm
(@robertonl)
Posts: 0
New Member
Topic starter
 

Realizei um teste. Posicionei o cursor após a ultima linha preenchida e selecionei até o final e mandei deletar, depois realizei a rotina que foi especificada e funcionou perfeitamente

 
Postado : 25/04/2018 7:53 pm