+ Reply to Thread
Results 1 to 4 of 4

Delete rows if specific criteria not met.

  1. #1
    SITCFanTN
    Guest

    Delete rows if specific criteria not met.

    I have a spreadsheet with 8 columns. I want to delete all rows that don't
    have the text "Remittance" in column B. I would like to put the code in an
    existing macro. Is this very difficult? Thanks

  2. #2
    Chip Pearson
    Guest

    Re: Delete rows if specific criteria not met.

    Try

    Dim LastRow As Long
    Dim RowNdx As Long
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    For RowNdx = LastRow To 1 Step -1
    If Cells(RowNdx, "B") <> "Remittance" Then
    Rows(RowNdx).Delete
    End If
    Next RowNdx


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "SITCFanTN" <[email protected]> wrote in
    message
    news:[email protected]...
    >I have a spreadsheet with 8 columns. I want to delete all rows
    >that don't
    > have the text "Remittance" in column B. I would like to put
    > the code in an
    > existing macro. Is this very difficult? Thanks




  3. #3
    JMB
    Guest

    RE: Delete rows if specific criteria not met.

    One way:

    Sub test()
    Const strCriteria As String = "remittance"
    Dim rngData As Range
    Dim rngCell As Range
    Dim rngDelete As Range

    With Worksheets("Sheet1") '<<<<<Change
    Set rngData = Intersect(.UsedRange, .Columns(2))
    End With

    For Each rngCell In rngData
    If LCase(rngCell.Value) <> LCase(strCriteria) Then
    If rngDelete Is Nothing Then
    Set rngDelete = rngCell
    Else: Set rngDelete = Union(rngDelete, rngCell)
    End If
    End If
    Next rngCell

    If Not rngDelete Is Nothing Then _
    rngDelete.EntireRow.Delete

    End Sub


    "SITCFanTN" wrote:

    > I have a spreadsheet with 8 columns. I want to delete all rows that don't
    > have the text "Remittance" in column B. I would like to put the code in an
    > existing macro. Is this very difficult? Thanks


  4. #4
    Barb Reinhardt
    Guest

    Re: Delete rows if specific criteria not met.

    I've done this but don't have the code at home. If you haven't gotten an
    answer by tomorrow, I'll copy what I have then.

    "SITCFanTN" <[email protected]> wrote in message
    news:[email protected]...
    >I have a spreadsheet with 8 columns. I want to delete all rows that don't
    > have the text "Remittance" in column B. I would like to put the code in
    > an
    > existing macro. Is this very difficult? Thanks




+ 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