+ Reply to Thread
Results 1 to 5 of 5

Delete table rows in multiple table is specific range

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Delete table rows in multiple table is specific range

    Have a 13 Worksheet workbook
    12 are like attached (1 per month)
    Col A:Z contain tables that must be left alone

    Col AA:AX contain 5 different tables (The same position on each worksheet)
    Looking for a macro like below to delete any table row within these 5 tables that have a value of 0

    This works well but I have to enter each table#

    Sub DataTableDeleteRows()
    Dim j As Long
        
        With ActiveSheet.ListObjects("Table15")
            For j = .ListRows.Count To 1 Step -1
                If .ListRows(j).Range(1, .ListColumns("Correct").Index) = "0" Then _
                    .ListRows(j).Delete
            Next j
        End With
    End Sub
    Thanks for the assist
    Jim
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Delete table rows in multiple table is specific range

    See if below works.
    Sub DataTableDeleteRows()
    Dim j As Long
    Dim tbl As ListObject
    
    For Each tbl In ActiveSheet.ListObjects
        If Len(Split(tbl.Range(, 1).Address, "$")(1)) > 1 Then
            With tbl
                For j = .ListRows.Count To 1 Step -1
                    If .ListRows(j).Range(1, .ListColumns("Correct").Index) = "0" Then _
                        .ListRows(j).Delete
                Next j
            End With
        End If
    Next
    End Sub
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Re: Delete table rows in multiple table is specific range

    This works great!
    How are you telling it to only select AA:AX Tables?

    Thanks

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Delete table rows in multiple table is specific range

    If Len(Split(tbl.Range(, 1).Address, "$")(1)) > 1 Then
    Above if statement grabs address of first column of each table. Splits the returned string using "$".
    Then grabs 2nd array element (i.e. Column letters) and checks for it's length and if it's greater than 1 character.

    So, if table fell in A~Z range length returned will be 1, AA~ will be 2.

  5. #5
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Re: Delete table rows in multiple table is specific range

    That's sweet!
    Thanks for explaining

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to delete table rows in multiple sheets?
    By erthmill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-24-2016, 12:30 PM
  2. How to sort & delete specific rows in a excel table
    By MaheshK5277 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-01-2016, 07:00 AM
  3. [SOLVED] Delete Table Rows Based on Specific Text
    By gedwards913 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2015, 12:47 PM
  4. Replies: 1
    Last Post: 11-25-2014, 08:35 PM
  5. Delete a selected row or range of rows in an Excel Table
    By gkkakala in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2014, 12:29 PM
  6. Hiding Rows in Pivot Table with specific value range
    By eugeneevans in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 01-22-2014, 04:42 PM
  7. [SOLVED] delete alot of rows with a specific value from a table
    By uimhirADo in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-03-2013, 05:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1