即効テクニック

セル操作関連のテクニック

空白行を削除する

(Excel 97/2000)
サンプルマクロは、使用セル範囲のうち空白行を削除します。
Sub Sample()

Dim myRow As Long, myClm As Long
Dim myRng As Range

    With ActiveSheet.UsedRange
        For myRow = 1 To .Rows.Count
            For myClm = 1 To .Columns.Count
                If .Cells(myRow, myClm).Value _
                    <> vbNullString Then Exit For
            Next
            If myClm = .Columns.Count + 1 Then
                If myRng Is Nothing Then
                    Set myRng = .Rows(myRow).EntireRow
                Else
                    Set myRng = Union(myRng, .Rows(myRow).EntireRow)
                End If
            End If
        Next
    End With
    
    On Error Resume Next
    myRng.Delete

End Sub