Solved

Clear Cells from Specified Row in Excel

Posted on 2011-02-11
4
836 Views
Last Modified: 2012-05-11
I would like to clear the spreadsheet from the specified Row at the click of a Command Button

Example:
I would like to clear from Row 13 in the Sheet1 till end, as i have my Spreadsheet heading above the Row 13 which i dont want to clear

What would be the VBScript code for the above
0
Comment
Question by:srikanthv2322
  • 2
4 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 34874366

You can use the following code which will do what you are looking for...

Saurabh...
Sub cleardata()
    Dim lr As Long
    lr = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    If lr > 13 Then Rows("14:" & lr).ClearContents



End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:cdebel
ID: 34874666
You need it as VBScript or VBA for Excel?
0
 
LVL 10

Accepted Solution

by:
cdebel earned 250 total points
ID: 34874861
Well, if it's VBS you really need, here's how you do it...
just make sure that you change the c:\test.xlsm for the file that you need to clear the data.
Adjust the range properly, your sheet might have more rows & columns than that.

 
dim objExcel
dim objWorkbook
Dim objWorksheet

Set objExcel = CreateObject("EXCEL.APPLICATION")
Set objWorkbook = objExcel.Workbooks.Open("c:\test.xlsm")
Set objWorksheet= objWorkbook.Sheets(1)

objWorksheet.Range("A14:IV65535").ClearContents

objWorkbook.Close true
set objWorksheet = nothing
set objWorkbook = nothing
Set objExcel = nothing

Open in new window

0
 

Author Closing Comment

by:srikanthv2322
ID: 34876519
Thank You
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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