clearing cells

M

MJKelly

Hi,

Can you tell me what is wrong with this code?


wksDump.Range(Cells(2, 1), Cells(1000, 256)).ClearContents

If I put in wksdump.cells.clearcontents it clears the whole sheet. I
want to keep the data in row 1.

hope you can help.

Thanks,
Matt
 
D

Dave Peterson

Those Cells() don't refer to wksDump. If the code is in a general module, they
refer to the active sheet.

If the code is behind a worksheet, they refer to the sheet with the code:

Either:

wksDump.Range(wksdump.Cells(2, 1), wksdump.Cells(1000, 256)).ClearContents

or
with wksDump
.Range(.Cells(2, 1), .Cells(1000, 256)).ClearContents
end with

(notice the dots in front of .range() and both .cells().)

or even...

wksDump.Cells(2, 1).resize(999,256).clearcontents
 
A

Ak Man

With Sheets(wksDump)
..Range(Cells(2, 1), Cells(1000, 256)).ClearContents
End With

I'm assuming that wksDump is the name of a sheet...
 
Top