This is because you do not have qualified Cells(1, 1) with a worksheet object, and the same is true for Cells(10, 2) . For the code to work, it should look something like this:
Dim ws As Worksheet Set ws = Sheets("SheetName") Range(ws.Cells(1, 1), ws.Cells(10, 2)).ClearContents
As an alternative:
With Sheets("SheetName") Range(.Cells(1, 1), .Cells(10, 2)).ClearContents End With
EDIT: A Range object inherits a worksheet from Cells objects when code is run from a standard module or user form. If you use code from a worksheet code module, you will also need to qualify Range as follows:
ws.Range(ws.Cells(1, 1), ws.Cells(10, 2)).ClearContents
or
With Sheets("SheetName") .Range(.Cells(1, 1), .Cells(10, 2)).ClearContents End With
source share