Solved

Clear Cells from Specified Row in Excel

Posted on 2011-02-11
4
834 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

864 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

19 Experts available now in Live!

Get 1:1 Help Now