clear spreadsheet to last row

Posted on 2012-08-17
Last Modified: 2012-08-17
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")
      For iCols = 0 To qdf.OpenRecordset.Fields.Count - 1
            wks.Cells(1, iCols + 1).Value = qdf.OpenRecordset.Fields(iCols).Name

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

Open in new window

Question by:PeterBaileyUk
    LVL 92

    Accepted Solution

    If you need to clear out the whole sheet:


    Open in new window

    LVL 13

    Assisted Solution

    Developing on matthews,

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


    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now