Method Clear Contents of Object Range Failed

ardykav

Board Regular
Joined
Oct 18, 2015
Messages
172
Office Version
  1. 365
Platform
  1. Windows
Hi
I have the following simple code, never had an issue with it before but all of a sudden I am getting the "Method Clear Contents of Object Range Failed" run time error. From what I have read this isnt so much an error with the code but more to do with the system is that correct? If anyone knows a way around this it would be greatly appreciated

VBA Code:
Sub Newstepclean()

   
    Sheets("Calculations").Select
    Range("K2:N7000").Select
    Selection.ClearContents
    Range("K2").Select

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Use this code instead.
VBA Code:
Sub newStepClean()
Dim lastRow As Long, strCells As String
With Sheets("Calculations")
    .Activate
    lastRow = .Cells(.Rows.Count, "N").End(xlUp).Row
    strCells = "K2:N" & lastRow
    .Range(strCells).ClearContents
    .Range("K2").Select
End With
End Sub
 
Upvote 0
Is the sheet protected, or do you have merged cells within that range?
 
Upvote 0
Is the sheet protected, or do you have merged cells within that range?
No i checked all that and nothing like that in there, I have ran this code for months and nothing wrong with it and nothing has changed in the ranges mentioned in the code, however I have done some digging and it looks to be a more systematic failure, i tried the file on another Laptop and it works fine still. Anyone any ideas around this?
 
Upvote 0
first questions have to be, are the laptops the same, do they all connect to you network the same, do they all have the same operating system and software for excel, the errant laptop, does it allow the user to make changes, have the all got the latest version or do you use a range of excels
you could shorten your code
VBA Code:
Sub newStepClean()
    Application.EnableEvents = False
    Sheets("Calculations").Range("K2:N7000").ClearContents
    Application.EnableEvents = True
End Sub
 
Upvote 0
No idea why it would work on one computer, but not another. However does this work on both?
VBA Code:
Sheets("Calculations").Range("K2:N7000").ClearContents
 
Upvote 0
No idea why it would work on one computer, but not another. However does this work on both?
VBA Code:
Sheets("Calculations").Range("K2:N7000").ClearContents
No thats the thing, no variation of clear contents is working on both. As in on one all variations work and on another no variations work, If you take out that piece of code then it goes to another error "Automation error the object invoked has become disconnected from its clients"
 
Upvote 0
first questions have to be, are the laptops the same, do they all connect to you network the same, do they all have the same operating system and software for excel, the errant laptop, does it allow the user to make changes, have the all got the latest version or do you use a range of excels
you could shorten your code
VBA Code:
Sub newStepClean()
    Application.EnableEvents = False
    Sheets("Calculations").Range("K2:N7000").ClearContents
    Application.EnableEvents = True
End Sub
Answers are no to all but the thing is they both worked fine up to a certain point and then just a few days ago the workbook stopped working on one which is really strange. There hasnt been any wholesale changes to either laptop or the workbook either.
 
Upvote 0
Does
VBA Code:
Sheets("Calculations").Range("K2:N7000").Value = vbNullString
do what you want?
How about .Clear.

No, I can't think of why this would be failing
 
Upvote 0
Does
VBA Code:
Sheets("Calculations").Range("K2:N7000").Value = vbNullString
do what you want?
How about .Clear.

No, I can't think of why this would be failing
No, again I think its a system setting as any variation of clear contents works on one laptop but not another
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,153
Members
452,615
Latest member
bogeys2birdies

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