Solved

Clear Cells from Specified Row in Excel

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

706 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

18 Experts available now in Live!

Get 1:1 Help Now