2011年6月12日日曜日

Excel 指定したシートの指定行から最終入力行までクリア

Public Sub clear(sheetName As String, rowNum As Integer)
    Application.ScreenUpdating = False
    ThisWorkbook.Sheets(sheetName).Activate
   
    With ActiveSheet
        If .AutoFilterMode Then
            Selection.End(xlToRight).Select
            HeaderLastCol = Selection.Column
            .Range(.Cells(rowNum, 1), .Cells(rowNum, HeaderLastCol)).Select
            Selection.AutoFilter
        End If
    End With
   
    If ActiveCell.SpecialCells(xlLastCell).Row < rowNum Then
        Exit Sub
    End If
   
    ActiveSheet.Rows("1:" & ActiveCell.SpecialCells(xlLastCell).Row).Delete Shift:=xlUp
    Application.ScreenUpdating = True

End Sub

0 件のコメント:

コメントを投稿