Excel macro to delete all rows of data starting with row 2 from multiple sheets in a workbook

stressler

Board Regular
Joined
Jun 25, 2014
Messages
95
I am trying to come up with a macro to delete all rows of data starting with row two (1st row is a header row that I do not want to delete) on several worksheets within my document. The worksheet names are listed out specifically in my macro below. I was just playing around with the rows 2:6000 in the macro. I really want it to delete all rows of data starting with row 2 and going until the last row, each sheet listed could have a different number of rows on the sheet. I get a Compile error: Syntax error when I run it. Can someone tell me where I'm going wrong? I know where I'm getting my error, I just don't know how to fix it.

Sub DeleteRows()

Dim shtArr, i As Long

shtArr = Array("Not Covered", "No Run", "Not Completed", "Blocked", "Failed", "Not Testable", "Passed")

For i = LBound(shtArr) To UBound(shtArr)

Sheets(shtArr(i)).Rows(2:6000).EntireRow.Delete

Next i

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this

VBA Code:
Sub DeleteRows()
  Dim shtArr
  Application.ScreenUpdating = False
  shtArr = Array("Not Covered", "No Run", "Not Completed", "Blocked", "Failed", "Not Testable", "Passed") 
  Sheets(shtArr).Select
  Rows("2:" & Rows.Count).Select
  Selection.Clear
  Sheets(1).Select
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,813
Members
449,469
Latest member
Kingwi11y

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top