PDA

View Full Version : [SOLVED:] Delete row if it contains a certain criteria Please Help



MJKeenan
04-16-2017, 10:59 PM
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

offthelip
04-17-2017, 04:16 PM
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
Or Not (Lft = "7")

to
Or Lft = "7"


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

MJKeenan
04-24-2017, 07:09 AM
Thank you!!!