Avatar of romeiovasu
romeiovasu
 asked on

excel macro

Thank you for help in advance.
i need a help with a macro to delete the rows that match
SGMN4002 or SGMN4004 with is in column D.

and my original macro, it is to be added to the original macro
Rows("1:6").Delete

    Range("A:B,E:E,G:O,Q:Z,AB:AN").Delete
    Range("A1").Value = "POrderNo"
    Range("B1").Value = "Customer"
    Range("C1").Value = "ShiptoCode"
    Range("D1").Value = "VendorSKU"
    Range("E1").Value = "Serial"

    Cells.EntireColumn.AutoFit

    Dim i As Long
    i = 2
    Do Until i > Cells(Cells.Rows.Count, "A").End(xlUp).Row
        If Len(Cells(i, "a").Value) > 6 Then
            Rows(i).Delete
        Else
            i = i + 1
        End If


    Loop
Workbook5.xlsx
Microsoft Excel

Avatar of undefined
Last Comment
Saurabh Singh Teotia

8/22/2022 - Mon
Rgonzo1971

Hi,

pls try

Rows("1:6").Delete

     Range("A:B,E:E,G:O,Q:Z,AB:AN").Delete
     Range("A1").Value = "POrderNo"
     Range("B1").Value = "Customer"
     Range("C1").Value = "ShiptoCode"
     Range("D1").Value = "VendorSKU"
     Range("E1").Value = "Serial"

     Cells.EntireColumn.AutoFit

     Dim Idx As Long
     
     For Idx = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
         If Len(Cells(Idx, "a").Value) > 6 Or _
                Cells(Idx, "d").Value = "SGMN4002" Or Cells(Idx, "d").Value = "SGMN4004" Then
            Rows(Idx).Delete
         End If
     Next

Open in new window

Regards
romeiovasu

ASKER
i am adding one more column i am not getting an error, but the 3rd one is not deleting.

Rows("1:6").Delete

     Range("A:B,E:E,G:O,Q:Z,AB:AN").Delete
     Range("A1").Value = "POrderNo"
     Range("B1").Value = "Customer"
     Range("C1").Value = "ShiptoCode"
     Range("D1").Value = "VendorSKU"
     Range("E1").Value = "Serial"

     Cells.EntireColumn.AutoFit

     Dim Idx As Long
     
     For Idx = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
         If Len(Cells(Idx, "a").Value) > 6 Or _
                Cells(Idx, "d").Value = "SGMN4002" Or Cells(Idx, "d").Value = "SGMN4004" Or Cells(Idx, "d").Value = "SGMN4003”” _
                Then
            Rows(Idx).Delete
         End If
     Next

End Sub


is there any way i can the items into idx.
ASKER CERTIFIED SOLUTION
Saurabh Singh Teotia

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck