Consulting

Results 1 to 4 of 4

Thread: If 3 times greater than delete row

  1. #1

    If 3 times greater than delete row

    I need some help in writing a code that will delete rows where certain criteria are met.

    Column W has text in it
    Column R has whole numbers in it
    Column Q has whole numbers in it


    If Column W= TPRFM then
    If Column R is 3x greater than Column Q then
    Delete Row

    Here is what I have so far

     
    Dim jLastRow As Long
    Dim j As Integer
        jLastRow = Cells(Rows.Count, "U").End(xlUp).Row
        For j = jLastRow To 1 Step -1
        If Range("W" & j).Value = "TPRFM" Then
              .............................................
                Range("W" & j).EntireRow.Delete (xlUp)
            End If
        
        End If
    Next j

  2. #2
    i'm just a beginner but i would use the following

    [vba]
    Range("W2").select 'suppose you have labels in the first row
    do while ActiveCell <> ""
    if ActiveCell = "TPRFM" and ActiveCell.Offset(0,1) >= 3 * ActiveCell.Offset(0,2) then
    Activecell.Row.Delete
    end if
    ActiveCell.Offset(1,0).Select
    loop
    [/vba]

    or something like that

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim jLastRow As Long
    Dim j As Long
    jLastRow = Cells(Rows.Count, "U").End(xlUp).Row
    For j = jLastRow To 1 Step -1
    If Range("W" & j).Value = "TPRFM" Then
    If Cells(j, "R").Value >= Cells(j, "Q").Value * 3 Then

    Range("W" & j).EntireRow.Delete (xlUp)
    End If
    End If
    Next j
    [/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

  4. #4

    Thumbs up Solved

    It worked like a charm. Thank you so much for your help.


Posting Permissions

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