+ Reply to Thread
Results 1 to 6 of 6

Delete table rows where a cell in D contains certain numbers

Hybrid View

  1. #1
    Registered User
    Join Date
    02-15-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    5

    Question Delete table rows where a cell in D contains certain numbers

    Hi all,

    I'm stuck somewhere very silly (I'm sure), but I can't seem to be able to get my macro to work. I have a spreadsheet with all of our call centre's incoming calls. I need my macro to delete all the rows with calls received outside business hours (I have the hours in column D). This is what I was trying to use but it's not working:

    Sub removecallsoutsidebh()
    
     ' Remove calls outside business hours
       
            Range("D2").Select
        Application.ScreenUpdating = False
        With ActiveSheet.Range("D1", Range("D" & Rows.Count).End(xlUp))
            .AutoFilter Field:=1, Criteria1:=Array("1", "2", "3", "4", "5", "6", "7", "17", "18", "19", "20", "21", "22", "23"), Operator:=xlFilterValues
            .Offset(1).EntireRow.Delete
            .AutoFilter
        End With
        Application.ScreenUpdating = True
    
    End Sub
    Interestingly, the above worked when I wanted my macro to delete all the rows with calls made to our two fax numbers, as I don't need to monitor those. I used the same macro but with two values and it works perfectly. It deletes all the rows with calls made to our fax numbers. If it helps, that first macro runs before my data is converted into a table....not sure that changes anything.

    Any help will be greatly appreciated!

    Thank you!

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Delete table rows where a cell in D contains certain numbers

    I just tried it on a mock-up version and it worked as expected. How is column D formatted?
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    02-15-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    5

    Re: Delete table rows where a cell in D contains certain numbers

    Thanks for trying a mock-up! It was converted to General earlier in the macro:

    With Selection
    .NumberFormat = "General"
    .Value = .Value
    End With

    Is your data within a table?

  4. #4
    Registered User
    Join Date
    02-15-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    5

    Re: Delete table rows where a cell in D contains certain numbers

    I think I may know what's wrong....the macros I'm posting here are for data outside of a table. I created them before my data was transformed into a table and they were working.

    Does anyone know how to accomplish what I need if the values are within a table?

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Delete table rows where a cell in D contains certain numbers

    No, my data was not in a table. If I tried it in a table, it did not work correctly.

  6. #6
    Registered User
    Join Date
    02-15-2015
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    5

    Re: Delete table rows where a cell in D contains certain numbers

    That's what I thought. I just added a code to convert my table back to a range and then it worked. There has to be a way to do it within a table but I can't find it anywhere, so converting it back to a range seemed like the easiest fix for now.

    Thanks anyway!

+ 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. Rows delete formula as per range of cell values with counter to delete # rows
    By qureshi2016 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2017, 09:35 AM
  2. [SOLVED] Delete table rows in multiple table is specific range
    By 3345james in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-26-2017, 08:32 AM
  3. Delete all rows in table containing value from cell in another sheet
    By 5foot9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-29-2017, 05:59 PM
  4. [SOLVED] Delete entire row in table if cell in column P contains any value (numbers or text)
    By BuntyMac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-29-2016, 02:49 PM
  5. [SOLVED] Insert row numbers into column A, reflect correct row numbers when I add or delete rows
    By jcambell in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-31-2015, 02:18 PM
  6. Delete rows that do not contain numbers
    By vikings in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 04:32 PM
  7. [SOLVED] Delete the Rows If it is Blank cell below Table header "Status"
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2012, 05:55 AM

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