Solved

Deleting rows in a table

Posted on 2013-12-09
3
181 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now