A solução abaixo checa as linhas abaixo da linha 11 (o que poderá customizar), deletando quando encontra a linha totalmente em branco, bem como quando a coluna "C" estiver vazia.
Sub PreparePlan_DelAllBlankRows()
' Author: Date: Contact:' André Bernardes 23/01/2009 10:17 bernardess@gmail.comDim i As Long ' We use Long in case they have over 32.767 rows selected.With Application.Calculation = xlCalculationManual.ScreenUpdating = FalseFor i = 11 To ActiveSheet.UsedRange.Rows.CountIf Range("C" & i).Value = "" Then 'WorksheetFunction.CountA(Selection.Rows(i)) = 0 ThenRows(i).SelectSelection.Delete Shift:=xlUpEnd IfNext i.Calculation = xlCalculationAutomatic.ScreenUpdating = TrueEnd With
End SubOutro exemplo:
Sub DeleteBlankRows1()
'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'We turn off calculation and screenupdating to speed up the macro.With Application.Calculation = xlCalculationManual.ScreenUpdating = False'We work backwards because we are deleting rows.For i = Selection.Rows.Count To 1 Step -1If WorksheetFunction.CountA(Selection.Rows(i)) = 0 ThenSelection.Rows(i).EntireRow.DeleteEnd IfNext i.Calculation = xlCalculationAutomatic.ScreenUpdating = TrueEnd With
End Sub
Mais um exemplo:
Sub DeleteBlankRows2()
'Deletes the entire row within the selection if some of the cells WITHIN THE SELECTION contain no data.On Error Resume NextSelection.EntireRow.SpecialCells(xlBlanks).EntireRow.DeleteOn Error GoTo 0
End Sub
Terceiro exemplo:
Sub DeleteBlankRows3()
'Deletes the entire row within the selection if the ENTIRE row contains no data.Dim Rw As RangeIf WorksheetFunction.CountA(Selection) = 0 ThenMsgBox "No data found", vbOKOnly, "OzGrid.com"Exit SubEnd IfWith Application.Calculation = xlCalculationManual.ScreenUpdating = FalseSelection.SpecialCells(xlCellTypeBlanks).SelectFor Each Rw In Selection.RowsIf WorksheetFunction.CountA(Selection.EntireRow) = 0 ThenSelection.EntireRow.DeleteEnd IfNext Rw.Calculation = xlCalculationAutomatic.ScreenUpdating = TrueEnd With
End Sub
Quarto exemplo:
Sub MoveBlankRowsToBottom()
'Assumes the list has a headingWith Selection.Sort Key1:=.Cells(2, 1), Order1:=xlAscending, _Header:=xlYes, OrderCustom:=1, MatchCase:=False, _Orientation:=xlTopToBottomEnd WithEnd SubSub DeleteRowsBasedOnCriteria()'Assumes the list has a heading.With ActiveSheetIf .AutoFilterMode = False Then .Cells(1, 1).AutoFilter.Range("A1").AutoFilter Field:=1, Criteria1:="Delete".Range("A1").CurrentRegion.Offset(1, 0).SpecialCells _(xlCellTypeVisible).EntireRow.Delete.AutoFilterMode = FalseEnd With
End Sub
5º exemplo:
Sub DeleteRowsWithSpecifiedData()
'Looks in Column D and requires Column IV to be cleanColumns(4).EntireColumn.InsertWith Range("D1:D" & ActiveSheet.UsedRange.Rows.Count).FormulaR1C1 = "=IF(RC[1]="""","""",IF(RC[1]=""Not Needed"",NA()))".Value = .ValueOn Error Resume Next.SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.DeleteEnd WithOn Error GoTo 0Columns(4).EntireColumn.Delete
End Sub
Tags: Excel, Column, Coluna, Delete, Linha, Plan, Planilhas, Report, Row, rows,worksheet, lines
André Luiz Bernardes
A&A® - In Any Place.
Nenhum comentário:
Postar um comentário