De vez em quando a Microsoft é mãe. Além de fornecer a ferramenta (guardadas as devidas proporçõe$), fornece vários exemplos de como resolver os problemas com elas. Seria esse o valor agregado?
Enfim, mas uma dúvida frequente em emails de fóruns é pelo VBA conseguir excluir as linhas que estão em branco ou vazias em uma planilhas. Outros códigos já disponibilizados aqui no fórum já promovem a façanha com um pequeno ajuste. Mas, para quem quer um código mais focado, a própria Microsoft disponibiliza a seguinte Macro:
' The following code deletes blank rows from the active worksheet.
Dim Counter
Dim i As Integer
Sub DelRow()
' Input box to determine the total number of rows in the worksheet.
Counter = InputBox("Enter the total number of rows to process")
ActiveCell.Select
' Loops through the desired number of rows.
For i = 1 To Counter
' Checks to see if the active cell is blank.
If ActiveCell = "" Then
Selection.EntireRow.Delete
' Decrements count each time a row is deleted. This ensures
' that the macro will not run past the last row.
Counter = Counter - 1
Else
' Selects the next cell.
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub |
' The following code deletes blank rows from the active worksheet.
Dim Counter
Dim i As Integer
Sub DelRow()
' Input box to determine the total number of rows in the worksheet.
Counter = InputBox("Enter the total number of rows to process")
ActiveCell.Select
' Loops through the desired number of rows.
For i = 1 To Counter
' Checks to see if the active cell is blank.
If ActiveCell = "" Then
Selection.EntireRow.Delete
' Decrements count each time a row is deleted. This ensures
' that the macro will not run past the last row.
Counter = Counter - 1
Else
' Selects the next cell.
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub
A parte bacana é que o código, ao ser executado, ele mostra um InputBox solicitando a quantidade de linhas que serão processadas, ou avaliadas. É uma boa, pois você pode não querer varrer todas as linhas de uma planilha certo?
O link original é:
http://support.microsoft.com/kb/110759/pt-br
Bom proveito!