Solved

Deleting rows in a table

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
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.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

770 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