• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

clear spreadsheet to last row

I want to clear the spreadsheet but the code I have at present does not clear down properly leaving rows from before.

Set wks = Sheets("CWCodesToMatch")
      wks.Range("a1").CurrentRegion.ClearContents
      For iCols = 0 To qdf.OpenRecordset.Fields.Count - 1
            wks.Cells(1, iCols + 1).Value = qdf.OpenRecordset.Fields(iCols).Name
      Next

      wks.Range("A2").CopyFromRecordset qdf.OpenRecordset

Open in new window

0
PeterBaileyUk
Asked:
PeterBaileyUk
2 Solutions
 
Patrick MatthewsCommented:
If you need to clear out the whole sheet:

wks.Cells.ClearContents

Open in new window

0
 
Shanan212Commented:
Developing on matthews,

If you want to clear the formats and contents, it would be

wks.Cells.Clear

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now