Excel crashes after numerous range updates with run-time error 1004

whitehawk81

Board Regular
Joined
Sep 4, 2016
Messages
66
Hi there!
I'm currently getting run-time error 1004: "Unable to get the CurrentRegion property of the Range class" within following subroutine:

VBA Code:
Sub clearData()
Dim modDataRng As Range

Set modDataRng = Sheet2.Range("B4:B7")

If WorksheetFunction.CountA(modDataRng) > 0 Then
    modDataRng.ClearContents
End If

If WorksheetFunction.CountA(Sheet3.Range("A:A")) > 1 Then
    Sheet3.Range("A2").CurrentRegion.Offset(1).ClearContents   'I get the error at this line
End If

End Sub

The strange thing is, I only get this error after I selected a few entries in the upper userform listbox.
This issue started, when I changed the ranges to tables on the "Servers" sheet.
I also uploaded an example file to demonstrate the issue better.
You can open the userform with the "Manage Plan" button on "Planlist" sheet.
I suspect, that it has to do something with the tablerange updates.
Do you have an idea, what could cause this issue?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I do not have the ability to download/view your file from my current location, but if you put this line of code above the one returning the error, can you let us know what it returns when you run the code?
VBA Code:
MsgBox Sheet3.Range("A2").CurrentRegion.Address
 
Upvote 0
I do not have the ability to download/view your file from my current location, but if you put this line of code above the one returning the error, can you let us know what it returns when you run the code?
VBA Code:
MsgBox Sheet3.Range("A2").CurrentRegion.Address
I get the range address: $A$1:$F$12, which is correct.
 
Upvote 0
OK, now what if you add the "Offset" piece to it, i.e.
VBA Code:
MsgBox Sheet3.Range("A2").CurrentRegion.Offset(1).Address

Does that still return a value without errors?
Do you have any merged cells or locked cells in that range that would prevent the values from being cleared?
 
Upvote 0
OK, now what if you add the "Offset" piece to it, i.e.
VBA Code:
MsgBox Sheet3.Range("A2").CurrentRegion.Offset(1).Address

Does that still return a value without errors?
Do you have any merged cells or locked cells in that range that would prevent the values from being cleared?
I also get the correct range $A$2:$F$13 with the offset funcion.
There are no locked or merged cells, no formulas or formatting applied within the range.
 
Upvote 0
Hmmm... I am not sure then.
Later on tonight, I will have access to my home computer, and I will see if I can download your file then, and take a look to see if I can see what is going on.

Just for kicks, try this one last thing. Add in this line of code (in red) and see if it makes any difference.
Rich (BB code):
If WorksheetFunction.CountA(Sheet3.Range("A:A")) > 1 Then
    Sheet3.Activate
    Sheet3.Range("A2").CurrentRegion.Offset(1).ClearContents   'I get the error at this line
End If

By the way, Sheet3 isn't hidden, is it?
 
Upvote 0
Hmmm... I am not sure then.
Later on tonight, I will have access to my home computer, and I will see if I can download your file then, and take a look to see if I can see what is going on.

Just for kicks, try this one last thing. Add in this line of code (in red) and see if it makes any difference.
Rich (BB code):
If WorksheetFunction.CountA(Sheet3.Range("A:A")) > 1 Then
    Sheet3.Activate
    Sheet3.Range("A2").CurrentRegion.Offset(1).ClearContents   'I get the error at this line
End If

By the way, Sheet3 isn't hidden, is it?
Thanks! I put the range address into a variable and added it to the watchlist. When the error occurs, the address stays empty. But then Excel crashes completely.
It's like the macro would get into an infinite loop.
 
Upvote 0
Thanks! I put the range address into a variable and added it to the watchlist. When the error occurs, the address stays empty. But then Excel crashes completely.
It's like the macro would get into an infinite loop.
OK, that is good to know. Then I think you should be able to use an IF...THEN statement to check to see if the address is empty, and if it is, then skip that step (and only run it if it is not empty).
 
Upvote 0
OK, that is good to know. Then I think you should be able to use an IF...THEN statement to check to see if the address is empty, and if it is, then skip that step (and only run it if it is not empty).
It was a nice idea. I don't get the error with the range address now, but Excel still crashes.
 
Upvote 0
Is this the only code you are running when it crashes, or is there any automated code which may also be running?
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,094
Latest member
bsb1122

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