2012-09-15 03:05:46 +0000 2012-09-15 03:05:46 +0000
24
24
Advertisement

Excel: Eliminar linha se a célula em determinada coluna estiver em branco?

Advertisement

Eu sou um novato completo no Excel, por isso desculpem-me se isto é algo fácil de fazer. Procurei muitas opções mas não consegui encontrar o que precisava.

Basicamente, quero apagar todas as linhas que não contêm um valor na coluna C. Como é que eu faria isto?

Estou a fazer isto manualmente neste momento para mais de 5000 produtos e isso está a deixar-me louco.

Advertisement
Advertisement

Respostas (4)

34
34
34
2012-09-15 06:08:10 +0000

Pode fazê-lo muito rapidamente se as células estiverem verdadeiramente em branco usando SpecialCells

Manual

  • Seleccione a coluna C
  • Prima F5, depois Special
  • Verifique Blanks, depois OK (veja este passo na imagem ao fundo)
  • Apague as linhas que estão agora seleccionadas (e. g. clique com o botão direito do rato na selecção > Delete cells… > Entire row or via the ribbon (see second screenshot))

VBA

Sub QuickCull()
    On Error Resume Next
    Columns("C").SpecialCells(xlBlanks).EntireRow.Delete
End Sub

9
9
9
2012-09-15 03:41:57 +0000

Aqui está um método manual fácil

  1. Aplique um Auto Filter na sua folha
  2. Filtrar na coluna C Em branco
  3. Seleccione todas as filas visíveis
  4. Eliminar Linhas
  5. Remover filtro

Este processo pode ser automatizado com VBA, se necessário. Tente executar o macro-gravador para começar

0
Advertisement
0
0
2016-02-19 16:18:47 +0000
Advertisement

Isto deve funcionar.

Columns("C:C").Select
Set rngRange = Selection.CurrentRegion
lngNumRows = rngRange.Rows.Count
lngFirstRow = rngRange.Row
lngLastRow = lngFirstRow + lngNumRows - 1
lngCompareColumn = ActiveCell.Column
For lngCurrentRow = lngLastRow To lngFirstRow Step -1
If (Cells(lngCurrentRow, lngCompareColumn).Text = "") Then _
Rows(lngCurrentRow).Delete
Next lngCurrentRow
-1
-1
-1
2015-03-22 11:48:37 +0000

Pode colocar este código no Módulo Folha (Separador Rato Direito Clique na Folha e seleccione “Ver Código”):

Sub Delete_Blank_Rows()

'Deletes the entire row within the selection if the ENTIRE row contains no data.

'We use Long in case they have over 32,767 rows selected.

Dim i As Long
Dim LastRow As Integer

'We turn off calculation and screenupdating to speed up the macro.

 With Application
     .Calculation = xlCalculationManual
     .ScreenUpdating = False

     'Reduce the work on the calc and define the range

     LastRow = Range("A" & Rows.Count).End(xlUp).Row
     Range("A2:A" & LastRow).Select

     'We work backwards because we are deleting rows.

     For i = Selection.Rows.Count To 1 Step -1
          If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
              Selection.Rows(i).EntireRow.Delete
          End If
     Next i

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With

End Sub
Advertisement

Questões relacionadas

6
13
9
10
3
Advertisement