Automatic delete vendor code and sorting to time

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

Automatic delete vendor code and sorting to time

Post by PRADEEPB270 »

I have a file with some datas and want to required a VBA code working to meet the following needs:-

Please refer the attach file for more clarifications.

1-Delete all rows having code '201596' from the column Inv. Pty i.e.Column C.Refer range C1184 to C1197.
2-Sorting according to 'time' i.e. column K.

Also please mention that if more codes to be delete in future,then, can it be easily process or not?
Regards

Pradeep Kumar Gupta
INDIA

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic delete vendor code and sorting to time

Post by HansV »

First, delete the empty row 3. Then run this macro:

Code: Select all

Sub DeleteRowsAndSort()
    Application.ScreenUpdating = False
    Range("B3").CurrentRegion.AutoFilter Field:=2, Criteria1:=Array("201596"), _
        Operator:=xlFilterValues
    Range("B3").CurrentRegion.Offset(1).EntireRow.Delete
    Range("B3").CurrentRegion.AutoFilter
    Range("B3").CurrentRegion.Sort Key1:=Range("K3"), Header:=xlYes
    Application.ScreenUpdating = True
End Sub
If you want to delete multiple codes, change Array("201596") to for example Array("201596", "219349", "100505"), listing all code that you want to delete.
Best wishes,
Hans

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

Re: Automatic delete vendor code and sorting to time

Post by PRADEEPB270 »

Thank you Hans sir.Codes are running fine as expected.Glad.
Regards

Pradeep Kumar Gupta
INDIA