+ Reply to Thread
Results 1 to 4 of 4

Help with deleting rows according to time value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-22-2012
    Location
    Bangalore, IND
    MS-Off Ver
    EXCEL 2010, 2007
    Posts
    90

    Help with deleting rows according to time value

    Hi all ,

    I am struck with a problem.. I have a sheet which generate a data of machines which runned over a day ,, I dont want the data which ran on mid night means 12.00 am to morning 8.00 am
    i want to delete those datas.

    please help

    Thanks in advance

    excel_time.xlsx
    Vipin Oceans

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Help with deleting rows according to time value

    Try this code on your test data first -
    Option Explicit
    
    Sub del_rows()
    Dim lrow As Long, i As Long
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = lrow To 2 Step -1
            If Hour(.Range("B" & i).Value) >= 0 And Hour(.Range("B" & i).Value) < 8 Then
                .Rows(i).Delete
                lrow = lrow - 1
            End If
        Next i
    End With
    End Sub
    Put the code in a standard module.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Help with deleting rows according to time value

    or
    Sub ertert()
    Application.ScreenUpdating = False
    Columns(1).Insert: Range("A1") = "temp"
    Range("A2:A" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=HOUR(RC[2])"
    With Range("A1").CurrentRegion
        .AutoFilter Field:=1, Criteria1:="<8"
        .Offset(1).SpecialCells(12).EntireRow.Delete
        .AutoFilter
    End With
    Columns(1).Delete
    Application.ScreenUpdating = True
    End Sub

  4. #4
    Registered User
    Join Date
    03-22-2012
    Location
    Bangalore, IND
    MS-Off Ver
    EXCEL 2010, 2007
    Posts
    90

    Re: Help with deleting rows according to time value

    Hi,
    Thank you so much its working but its giving an error atlast

    Run time error "13"
    type mismatch


    one more thing can u add one more condition which is " delte all the lines after 9pm " if possible . thank you so much rep added

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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