Consulting

Results 1 to 3 of 3

Thread: Delete row if it contains a certain criteria Please Help

  1. #1
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location

    Delete row if it contains a certain criteria Please Help

    Need to delete rows where the criteria in Column D does not start with the number 7 in the Identifier. I have a macro to remove N/A's but I need this macro updated to remove sku's that start with the number 7.

    Attached is the worksheet.

    Sub RemoveNA_AmountsFromOrderForm()
        Dim NAs As String
        Set sku = [d7]
        sku.Activate
        
        Do Until sku.Text = ""
            NAs = sku.Offset(1, 1) & sku.Offset(1, 2) & sku.Offset(1, 3) & _
            sku.Offset(1, 4) & sku.Offset(1, 6) & sku.Offset(1, 7) & sku.Offset(1, 8)
            
            'if the pricing row is all NAs then delete the pattern & pricing rows
            If NAs = "N/AN/AN/AN/AN/AN/AN/A" Then
                Set sku = ActiveCell.Offset(2, 0)
                Range(sku.Offset(-2, 0), sku.Offset(-1, 0)).EntireRow.Delete
            Else
                Set sku = ActiveCell.Offset(2, 0)
                sku.Activate
            End If
        Loop
     
    
    
    End Sub
    Attached Files Attached Files
    Last edited by MJKeenan; 04-16-2017 at 11:38 PM.

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    I wasn't sure whether you wanted to remove the lines starting with 7 or leave the lines starting with 7. This code leaves the lines starting with 7, if you want to remove then change
    [vba]Or Not (Lft = "7")
    [/vba]
    to
    [vba]Or Lft = "7"[/vba]


    [vba]Sub RemoveNA_AmountsFromOrderForm()
    Dim NAs As String
    Dim Lft As String
    Set sku = [d7]
    sku.Activate

    Do Until sku.Text = ""
    NAs = sku.Offset(1, 1) & sku.Offset(1, 2) & sku.Offset(1, 3) & _
    sku.Offset(1, 4) & sku.Offset(1, 6) & sku.Offset(1, 7) & sku.Offset(1, 8)
    Lft = Left(CStr(sku), 1)

    'if the pricing row is all NAs then delete the pattern & pricing rows
    If NAs = "N/AN/AN/AN/AN/AN/AN/A" Or Not (Lft = "7") Then
    Set sku = ActiveCell.Offset(2, 0)
    Range(sku.Offset(-2, 0), sku.Offset(-1, 0)).EntireRow.Delete
    Else
    Set sku = ActiveCell.Offset(2, 0)
    sku.Activate
    End If
    Loop



    End Sub
    [/vba]

  3. #3
    VBAX Regular
    Joined
    Apr 2017
    Posts
    13
    Location
    Thank you!!!

Posting Permissions

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