Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete All Excel Data Except for Row 1 1

Status
Not open for further replies.
Apr 3, 2003
180
US
Hello,
Can someone please help me with a small issue I am having, I need to delete all the information in an excel spreadsheet except for the first row which contains column headings. Thanks a bunch for your time.

"I hear and I forget. I see and I remember. I do and I understand."
- Confucius (551 BC - 479)
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I don't have anything yet, I am new to vbscript and need some sample code to get started.

"I hear and I forget. I see and I remember. I do and I understand."
- Confucius (551 BC - 479)
 
easy enough...
Code:
filePath = "c:\Test.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Open filePath
WScript.Sleep 5000

Set myRange = objExcel.Worksheets("Sheet1").Range("A1").CurrentRegion
i = myRange.Rows.Count
objExcel.Rows(2 & ":" & i).Delete

objExcel.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs filePath
objExcel.ActiveWorkbook.Close
objExcel.Quit
Set objExcel = Nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark, just what I needed and it works great.

"I hear and I forget. I see and I remember. I do and I understand."
- Confucius (551 BC - 479)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top