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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting rows in excel from vba

Status
Not open for further replies.

grmman

MIS
Sep 9, 2003
81
US
I want to be able to loop thru an excel workbook that has 20 sheets init and be able to delete the first row in each sheet.
Here is the code I have. it deletes all the rows(the first sheet only has 2 rows)in the first sheet.
Thanks


Code:
Set xlapp = GetObject(, "Excel.Application")
xlapp.Visible = False
Set xlwb = xlapp.Workbooks.Open("N:\ESE Development\PA E & S\Program\sheets\es_test.xls")
Set sheet = xlapp.ActiveWorkbook.Sheets(1)
z = 1
sheetcnt = xlapp.ActiveWorkbook.Sheets.Count


For z = 1 To sheetcnt
    Set sheet = xlapp.ActiveWorkbook.Sheets(z)
    MsgBox sheet.Name & " ::::" & z
    Rows(1).EntireRow.Delete
Next z
 
In you have charts in your workbooks, a safer way:
For Each sheet In xlapp.ActiveWorkbook.Worksheets
MsgBox sheet.Name & " ::::" & z
sheet.Rows(1).EntireRow.Delete
Next sheet

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top