Simplifying VBA code

ian0886

New Member
Joined
Dec 10, 2016
Messages
42
Hi Guys,

I have the below code written. But i'm trying to find ways to further shorter it. Could any kind soul please see if i can?
Code:
Sub BNP()'remove unwanted trades
    Dim c As Range
    Dim SrchRng
    
    Worksheets(1).Select
    Worksheets(1).Name = "XYZ"
    
    Application.DisplayAlerts = False
    Cells.EntireColumn.AutoFit
    Columns("P:P").TextToColumns Destination:=Range("P1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(5, 1)), TrailingMinusNumbers:=True
    
    SearchCol1 = "Cust"
    SearchCol2 = "Source"
    SearchCol3 = "Activity"
    
    Dim rng(1 To 3) As Range
    
    Set rng(1) = ActiveSheet.UsedRange.Find(SearchCol1, , xlValues, xlPart)
    Set rng(2) = ActiveSheet.UsedRange.Find(SearchCol2, , xlValues, xlWhole)
    Set rng(3) = ActiveSheet.UsedRange.Find(SearchCol3, , xlValues, xlWhole)
    
    With Worksheets("XYZ")
    .Range("A1").CurrentRegion.AutoFilter Field:=rng(1).Column, Criteria1:="11244", Operator:=xlOr, Criteria2:="NQAAA"
    .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilterMode = False
    
    .Range("A1").CurrentRegion.AutoFilter Field:=rng(1).Column, Criteria1:="WET*"
    .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilterMode = False


    .Range("A1").CurrentRegion.AutoFilter Field:=rng(2).Column, Criteria1:="DRY"
    .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilterMode = False
    
    .Range("A1").CurrentRegion.AutoFilter Field:=rng(3).Column, Criteria1:="C XL"
    .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    .AutoFilterMode = False
    End With
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,226,113
Messages
6,189,049
Members
453,522
Latest member
Seeker2025

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top