Excel "Cannot Complete Task With Available Resources" When Trying to Delete Rows

LadiesAndGentlemen

New Member
Joined
Jul 5, 2012
Messages
14
Hi everyone,

I have VBA code that attempts to delete an entire row from my worksheet:
Code:
Cells(3,1).Select
Selection.EntireRow.Delete

This works fine on small data sets, but on larger data sets it gives me the error message, "Excel cannot complete this task with available resources". This happens even when I try to do the deletion manually (without VBA code). Clearly, the code itself is not the problem.

My document has about 250,000 rows and 2,500 columns. While this is big, it is significantly smaller than Excel's documented limit of 1,048,576 rows and 16,384 columns.

I am using Excel 2007. My computer has 2GB of RAM but even when I try it on a computer which has 8GB of RAM it gives me the same error. If I "ClearContents" instead of "Delete" it works fine. For my purposes, however, deletion is entirely necessary.

Why won't Excel allow me to do this simple thing and what are possible workarounds? Any help would be greatly appreciated.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
If you want to try the tip from Dazzawm then the process is

Open Installed Updates by clicking the Start button
4f6cbd09-148c-4dd8-b1f2-48f232a2fd33_47.png
, clicking Control Panel, clicking Programs, and then, under Programs and Features, clicking View installed updates.

Click the update that you want to remove, and then click Uninstall.
18abb370-ac1e-4b6b-b663-e028a75bf05b_41.png
If you are prompted for an administrator password or confirmation, type the password or provide confirmation.
 
Upvote 0
Thank you all for your help! Although I was not able to get any of the suggestions to work, I did find a work-around. Basically I copied the cells I needed rather than delete the ones I didn't need.

Thanks again!
 
Upvote 0
I know you have found a workaround but I am intrigued that you can copy/paste yet not delete, If you get a chance can you try running the code below on your original data an see if it gives you
I now have a document of 525,000 rows and exactly 2,500 columns

Code:
Sub ShowUsedRange()
Dim sheet As Worksheet
Dim row_min As Integer
Dim row_max As Integer
Dim col_min As Integer
Dim col_max As Integer


    ' Select the used range.
    Set sheet = ActiveSheet
    sheet.UsedRange.Select


    ' Display the range's rows and columns.
    row_min = sheet.UsedRange.Row
    row_max = row_min + sheet.UsedRange.Rows.Count - 1
    col_min = sheet.UsedRange.Column
    col_max = col_min + sheet.UsedRange.Columns.Count - 1


    MsgBox "Rows " & row_min & " - " & row_max & vbCrLf & _
           "Columns: " & col_min & " - " & col_max
End Sub
 
Upvote 0
Thank you all for your help! Although I was not able to get any of the suggestions to work, I did find a work-around. Basically I copied the cells I needed rather than delete the ones I didn't need.

Thanks again!

Did you do as I said? I am surprised that didnt work.
 
Upvote 0
Thank you all for your help! Although I was not able to get any of the suggestions to work, I did find a work-around. Basically I copied the cells I needed rather than delete the ones I didn't need.

Thanks again!

Your Solution confirmed that this was a calculation issue next time turn off automatic calculation before deleting row and then back on after deleting the row.
 
Upvote 0
The calculation is the most likely cause due to the number of formulas but it is not the only possibility. For instance there could be hidden objects outside the expected range or even both combined.
 
Upvote 0
Did you do as I said? I am surprised that didnt work.

I'm using Excel 2007 rather than 2010 so I wasn't able to use the exact method you suggested. I did, however, do some research and found the corresponding update for 2007 and that did not fix the issue (though there is a chance I messed up somewhere in the process. I also downloaded a hotfix to no avail.
Your Solution confirmed that this was a calculation issue next time turn off automatic calculation before deleting row and then back on after deleting the row.
How would I turn off automatic calculation? The reason I don’t think this was the issue is because my worksheet does not have any formulas. Everything is of type value and there are no cell references unless they are hidden deep under the hood.

I know you have found a workaround but I am intrigued that you can copy/paste yet not delete, If you get a chance can you try running the code below on your original data an see if it gives you

Code:
Sub ShowUsedRange()
Dim sheet As Worksheet
Dim row_min As Integer
Dim row_max As Integer
Dim col_min As Integer
Dim col_max As Integer


    ' Select the used range.
    Set sheet = ActiveSheet
    sheet.UsedRange.Select


    ' Display the range's rows and columns.
    row_min = sheet.UsedRange.Row
    row_max = row_min + sheet.UsedRange.Rows.Count - 1
    col_min = sheet.UsedRange.Column
    col_max = col_min + sheet.UsedRange.Columns.Count - 1


    MsgBox "Rows " & row_min & " - " & row_max & vbCrLf & _
           "Columns: " & col_min & " - " & col_max
End Sub

Just tried this and it actually gives me Run-time error '6' Overflow on the line " row_max = row_min + sheet.UsedRange.Rows.Count - 1." I have run a simple "ActiveSheet.UsedRange.Rows.Count" calculation for rows and columns to confirm that I was indeed dealing with 500,00 rows and 2,500 columns.
 
Upvote 0
I just tried putting the document into Manual Calculation Mode instead of Automatic and it didn't make a difference. I'm not sure if my manual mode is working though because if I type "=4*5" into a cell and hit enter, it still replaces it with "20". What is manual mode supposed to do?
 
Upvote 0
The reason the code I posted errors out is probably because I did not change the integers to Long. I am on my phone at the moment so can't post code. If you change the integers to Long it should run.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top