?
Solved

Clear an Excel sheet using VB.Net

Posted on 2006-04-06
2
Medium Priority
?
777 Views
Last Modified: 2008-02-01
I have added a "clear" button to an excel sheet and I need the VB.Net code to clear the contents of the entire sheet, minus the column headings (1 line).  The ending cell will constantly be changing each time the user uses the "clear" button.
0
Comment
Question by:RFGNaper
2 Comments
 
LVL 4

Accepted Solution

by:
AndyAelbrecht earned 2000 total points
ID: 16391818
i'm going to suppose you already figured out how to select the worksheet you want to do this on.

with .worksheet
    .Rows("2:2").Select
    .Range(Selection, Selection.End(xlDown)).Select
    .Selection.ClearContents
end with

this clears the complete worksheet except for the first row.

cheers,
Andy
0
 
LVL 44

Expert Comment

by:bruintje
ID: 16391838
Hello RFGNaper,

if there is a continuous column like A or B you can get do it like

assuming you already have your variables declared

'this will give you the last row
intRowCount = mySheet.[A1].End(xlDown).Row
'this will clear all cells in the sheet except the first
mySheet.Range("A2:Z" & intRowCount).Clear ' Z is you last column

hope this helps a bit
bruintje
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 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