简体   繁体   中英

How to clear data between first and last row in excel column

I need to clear data between first cell and last cell in a excel column. I tried this code, but it deletes the data from the entire sheet, I need only for a specific column.

Sub DeleteRow()
Dim i1 As Long
Dim iMax As Long
iMax = Cells.SpecialCells(xlCellTypeLastCell).row

For i1 = iMax - 1 To 2 Step - 1
    Rows(i1).EntireRow.Clear
Next i1

End Sub

This would clear content between the first row and the last row in column A.

Sub ClearRows()
    Dim lastRow As Long

    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("A2:A" & lastRow - 1).ClearContents
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM