I wonder why the following line gave "Applicaiton-defined or Object-defined error"?
If Sheet6 is selected, this line runs fine. No error message. If, instead, other sheet is selected, Excel throws the error message.
ThisWorkbook.Sheets("Sheet6").Range(Cells(1, 2), Cells(12, 1000).End(xlToLeft)).ClearContents
You need to qualify all your objects with your worksheet
With ThisWorkbook.Worksheets("Sheet6") .Range(.Cells(1, 2), .Cells(12, 1000).End(xlToLeft)).ClearContents End With
You didn't qualify
Cells() with your worksheet, so it pulls from the
ActiveSheet instead of
So, remember that when your thinking "It only works when it's on that sheet" then this is going to be the issue.