简体   繁体   中英

Last used cell in excel is so large excel crashes when trying to delete excess columns and rows

I have a worksheet where the last used cell is said to be cells(1048381,BH). I know I'm supposed to delete all rows (and columns, but less relevant in this particular case as all columns through BH are actually be used) until the final row, but the final row is such a large number that excel (64-bit) crashes when I go to fix the problem. Any recommendations?

Thanks!

You don't actually have to delete the rows between the last valid row of data and a rogue last cell. Using Home, Editing, Clear, Clear All is sufficient and is much less calculation intensive.

Here is some code that performs the same action on a rogue populated cell.

Option Explicit

Sub resetRogueRow()

    Dim lr As Long, nr As Long

    With Worksheets("sheet2")

        lr = .Cells.Find(What:="*", _
                         After:=.Cells(1), _
                         LookAt:=xlWhole, _
                         LookIn:=xlFormulas, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlPrevious, _
                         MatchCase:=False).Row
        nr = .Cells.Find(What:="*", _
                         After:=.Cells(lr, 1), _
                         LookAt:=xlWhole, _
                         LookIn:=xlFormulas, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlPrevious, _
                         MatchCase:=False).Row

        .Cells(nr + 1, "A").Resize(lr - nr, 1).EntireColumn.Clear

    End With
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