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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

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