Excel VBA delete rows based on multiple column criteria

后端 未结 1 394
南笙
南笙 2020-12-21 21:32

I am trying to do some cuts to a sheet of data based on if a row meets 2 criteria in different columns, i.e. if the value in column D is > -2 and if the value in the adjacen

相关标签:
1条回答
  • 2020-12-21 22:04

    I'm not sure how you want to handle blank cells or text in column headings but I would propose this modification.

    Sub Cuts()
        Dim wb1 As Workbook
        Dim lr As Long, i As Long
        Set wb1 = Workbooks(“ovaryGisticARRAYRNAseq.final.xlsx")
        With wb1.Sheets("Cuts")
            lr = Application.Max(.Cells(Rows.Count, 4).End(xlUp).Row, _
              .Cells(Rows.Count, 6).End(xlUp).Row)
            For i = lr To 1 Step -1
                If .Cells(i, 4).Value > -2 And _
                  (.Cells(i, 6).Value > -2 Or UCase(.Cells(i, 6).Value) = "NA") Then
                    .Rows(i).EntireRow.Delete
                End If
            Next i
        End With
    End Sub
    
    0 讨论(0)
提交回复
热议问题