+ Reply to Thread
Results 1 to 10 of 10

Find rows and delete them based on multiple criteria

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Find rows and delete them based on multiple criteria

    Well, I assumed the times reside in Column B. If not then replace it with whatever you want in the below code.

    Sub DeleteTimes()
    Dim h As Double, r As Integer, i As Integer
    r = Cells.SpecialCells(xlCellTypeLastCell).Row
    With ActiveSheet
        For i = r To 1 Step -1
            h = VBA.Hour(.Range("B" & i)) + 60 * VBA.Minute(.Range("B" & i))
            If h < 7 Or h > 19 Then .Rows(i).EntireRow.Delete
            If h > 10 And h < 16 Then .Rows(i).EntireRow.Delete
        Next
    End With
    End Sub
    Last edited by Kelshaer; 01-31-2012 at 09:54 AM.
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  2. #2
    Forum Contributor
    Join Date
    03-21-2007
    Posts
    118

    Re: Find rows and delete them based on multiple criteria

    Quote Originally Posted by Kelshaer View Post
    Well, I assumed the times reside in Column B. If not then replace it with whatever you want in the below code.
    Thanks, this seems to be working but it's taking a long time as I've got '000s of rows. Isn't there any way to amend the macro in OP as it uses the Filter which speeds things up? It works when I type one criterion, but not for multiple ones.
    EDIT: Something seems to be wrong in the macro you posted with how it handles time as it whittled down 15000 rows to about 80!. when there should be a few thousand.
    _-= Have you google'd your question before posting? =-_
    _-= Have you Searched the forum for an answer before posting? =-_

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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