Solved

Deleting rows in a table

Posted on 2013-12-09
3
186 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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 how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

726 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