Consulting

Results 1 to 3 of 3

Thread: Solved: Delete the Row based on criteria

  1. #1
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location

    Solved: Delete the Row based on criteria

    All,

    Can you advise me how to delete row if meet criteria.

    Many thanks in advance.
    Rgds, Harto

    [VBA]Sub DeleteUnprintedList()
    Dim RangeToBeDeleted As Range
    Dim xRowsCount As Long
    Dim r As Long

    Sheets(1).Activate
    On Error Resume Next
    Set RangeToBeDeleted = ActiveSheet.Range([B2], [B2].End(xlDown))


    xRowsCount = RangeToBeDeleted.Rows.Count

    Application.Calculation = xlCalculationManual

    For r = xRowsCount To 1 Step -1

    If Left(RangeToBeDeleted(r, 2), 4).Value = "9427" Or "9393" Or "9454" Or "9545" Or "9446" Or "9428" Or "9523" Then
    RangeToBeDeleted(r, 2).EntireRow.Delete
    End If
    Next r

    Application.Calculation = xlCalculationAutomatic
    End Sub
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I fear this might be overdoing it, it only left one row of data

    [vba]

    Sub DeleteUnprintedList()
    Dim RangeToBeDeleted As Range
    Dim xRowsCount As Long
    Dim r As Long
    Dim CheckValue As String

    Sheets(1).Activate
    On Error Resume Next
    Set RangeToBeDeleted = ActiveSheet.Range([B2], [B2].End(xlDown))

    ' Mendelete rows harus dari bawah, supaya codingnya tidak rumit ..
    xRowsCount = RangeToBeDeleted.Rows.Count

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    For r = xRowsCount To 1 Step -1

    'Cukup 1 cell (terkiri/kolom 1) saja yg menjadi syarat.. tetapi dengan berbagai kondisi
    CheckValue = Left$(RangeToBeDeleted(r, 2).Value, 4)
    If CheckValue = "9427" Or CheckValue = "9393" Or CheckValue = "9454" Or _
    CheckValue = "9545" Or CheckValue = "9446" Or CheckValue = "9428" Or "CheckValue = 9523" Then

    Rows(r).Delete
    End If
    Next r

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    Hi Bob,

    Thank you for quick response and wonderful code.
    you are my master.
    Again and againg. Thank you so much.
    Best, harto

Posting Permissions

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