Removing prompt when using VBA to delete all but first row in table

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
303
Office Version
  1. 365
My code deletes all but the first row of my table, tblETS. But when the code runs I get prompted with "Delete entire sheet row?" I've deleted rows like this before but this is the first time it's prompting me.

How can I keep that prompt from popping up?

VBA Code:
Private Sub PrepMyTable()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Application.ScreenUpdating = False
    Set wsCopy = Worksheets("Data Validation")
    Set wsDest = Worksheets("Detailed ETS Estimation")
    On Error Resume Next
    wsCopy.Visible = xlSheetVisible
    wsDest.ListObjects("tblETS").DataBodyRange.Rows.Delete
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Do you have a filter applied to the table ?
If you do, ShowAllData before trying to delete the rows.
VBA Code:
    With wsDest.ListObjects("tblETS")
        If .ShowAutoFilter = True Then
            .AutoFilter.ShowAllData
        End If
        .DataBodyRange.Rows.Delete
    End With
 
Last edited:
Upvote 1
Solution
Do you have a filter applied to the table ?
If you do, ShowAllData before trying to delete the rows.
VBA Code:
    With wsDest.ListObjects("tblETS")
        If .ShowAutoFilter = True Then
            .AutoFilter.ShowAllData
        End If
        .DataBodyRange.Rows.Delete
    End With
Hi Alex and thanks.

Well, I didn't have a filter in effect, but your code seemed to solve my problem anyway. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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