Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Clear Cells from Specified Row in Excel

Posted on 2011-02-11
4
Medium Priority
?
843 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Christian de Bellefeuille
ID: 34874666
You need it as VBScript or VBA for Excel?
0
 
LVL 10

Accepted Solution

by:
Christian de Bellefeuille earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
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…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

670 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