Solved

Deleting rows in a table

Posted on 2013-12-09
3
185 Views
Last Modified: 2013-12-24
Hello Experts,

I am trying to delete information in a table once it has been filtered.
All the visible information that appears in the table after it was filtered has to be deleted (except for the header).

I used the following code:
Sheets("Initiative Summary").ListObjects("InitiativeTbl").listColumns("Functional Area").databodyrange.specialcells(xlCellTypeVisible).Delete

The code works fine unless the first item in the table is invisible. In this case it deletes the entire table including the header.

Could you please help me fix this?

Thanks
0
Comment
Question by:jmac001
3 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39707232
Does this have to be with VBA? Otherwise you can do this:
- Select the top left data cell to be deleted
- Hit Shift+Ctrl+Down
- Hit Ctrl+-
- Select entire row

You will then see the unfiltered results minus the rows you've just deleted.

Edit: To quickly get to the top left hit Ctrl+Up,Left (possibly a few times if you have empty cells) or alternatively Ctrl+Home but I typically find my hand over the arrow keys when I'm using Excel.
0
 

Author Comment

by:jmac001
ID: 39707257
Angelp1ay, it has to be a macro to automatically perform these operations across multiple worksheets.

Thanks
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39709588
Something like this ought to do it:

Sub DeleteThem()
    
    Dim lo As ListObject
    Dim rng As Range
    
    Set lo = ActiveSheet.ListObjects(1)
    
    With lo.ListRows
        Set rng = Range(.Item(1).Range.Cells(1), .Item(.Count).Range.Cells(1)).SpecialCells(xlCellTypeVisible)
        Application.DisplayAlerts = False
        rng.Delete
        Application.DisplayAlerts = True
    End With
    
    MsgBox "Done"
    
End Sub

Open in new window


Just be aware that if you have more than ~16000 rows, SpecialCells can be unreliable...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question