Run-time error '1004' VBA delete rows from an array of sheets

Js Smith

New Member
Joined
Jul 24, 2020
Messages
44
Office Version
  1. 2010
Platform
  1. Windows
Hi all, hope you had a great weekend.
I'm writing another VBA to automate my coworker's manual processes and this I've got a syntax error but the Monday brain isn't working. My first step is to ensure old data is gone before importing new data on a few of the many sheets available.
On sheets "EPIC" and "EPIC_FEAT" I want to delete row 3 to wherever the end of the data is. This is what I've got so far

VBA Code:
Sub DeleteRows()
Dim shArr, i As Long, xx As Long

shArr = Array("EPIC", "EPIC_FEAT")
 xx = Range("A3").End(xlDown).Select

For i = LBound(shArr) To UBound(shArr)
  Sheets(shArr(i)).Selection(xx).EntireRow.Delete
Next i
End Sub

I get the Run-time error '1004': Application-defined or object-defined error at
Code:
Sheets(shtArr(i)).Selection(xx).EntireRow.Delete
I tried also
Code:
Sheets(shtArr(i)).Rows(xx).EntireRow.Delete
. It seems like this code is very close but can figure the issue out..

They don't let me install apps so can't upload a Mini-sheet but headers are on row there are multiple columns; something like below:

NameKeySummary
hgfgjhdsfafsafadsfasdfasfdasfd
fghjfhjasdfasdfsaf
fhjgdsfasdfadsfasfd
sfdgdsgsdfsadf
sdfdsfgsdfasdf
sdfgdsgfasfdadsfasdfsafd
sdfgdsgfasdfasf
sdfgdsgfadfadsfasdffsda
gsdgfasfdsafd


How would you do this task? Thanks, as always, for helping me learn! :)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This should do it.

VBA Code:
Dim shArr, i As Long

shArr = Array("EPIC", "EPIC_FEAT")

For i = LBound(shArr) To UBound(shArr)
  With Sheets(shArr(i))
  .Range("A3:A" & Cells(Rows.Count, "A").End(xlUp).Row).EntireRow.Delete
  End With
Next i
 
Upvote 0
Hi @Js Smith:

Please try this:

VBA Code:
Sub DeleteRows()
  Dim sh As Variant
  For Each sh In Array("EPIC", "EPIC_FEAT")
    Sheets(sh).Rows("3:" & Rows.Count).Delete
  Next
End Sub

I hope to hear from you soon.
Respectfully
Dante Amor
 
Upvote 0
Solution
Hi @Js Smith:

Please try this:

VBA Code:
Sub DeleteRows()
  Dim sh As Variant
  For Each sh In Array("EPIC", "EPIC_FEAT")
    Sheets(sh).Rows("3:" & Rows.Count).Delete
  Next
End Sub

I hope to hear from you soon.
Respectfully
Dante Amor
Perfect! Thanks for straightening me out.
 
Upvote 1

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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