Why is this code not deleting?

cspengel

Board Regular
Joined
Oct 29, 2022
Messages
173
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I use this same code multiple times throughout my workbook with different columns, but only having problems with this one and I don't know why. Any insight would be appreciated. The purpose is replace values in column AP that are less than 1 with the number "7". The 7 is then replaced with #N/A. The values in AP are then sorted in descending order so #N/A is at top. It is then supposed to filter and delete. My set range is G:AP.

VBA Code:
'''''''''''''''''''''''''''NO MVP UNDER 15 PROB AND 15 TARGET
 lLastRowDeDuped = Cells(Rows.Count, lFirstWriteColumn).End(xlUp).Row
    ''Add MVP Column (column AP)
    Cells(1, lLastWriteColumn + 31).Value = ChrW(931) & " MVP"
  
  With Range(Cells(2, lLastWriteColumn + 31), Cells(lLastRowDeDuped, lLastWriteColumn + 31))
   
    .Formula2R1C1 = "=COUNTIFS(RC[-15],"">15"",RC[-10],"">15"")"
        Application.Calculate
        .Value = .Value
     End With
        With Range("AP2", Range("AP" & Rows.Count).End(xlUp))
       .Value = Evaluate(Replace("if(@<1,7,if(@="""","""",@))", "@", .Address))
        End With
       
        LR = Range("G" & Rows.Count).End(xlUp).Row
Set c = Intersect(ActiveSheet.UsedRange, Range("AP:AP"))

c.Replace What:="7", replacement:="#N/A", LookAt:=xlWhole
On Error Resume Next
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Add2 Key:=Range( _
        "AP2:AP400000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Worksheet").Sort
        .SetRange Range("G1:AP400000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("AP1").CurrentRegion.Select
    With Selection
    ActiveSheet.Range("$G$1:$AP$400000").AutoFilter Field:=36, Criteria1:="#N/A"
    j = WorksheetFunction.Count(ActiveSheet.Range("$G$1:$AP$400000").Cells.SpecialCells(xlCellTypeVisible))
    If j = 0 Then
    ActiveSheet.AutoFilterMode = False
    GoTo Continue_Code14
   
    End If
   
    .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    ActiveSheet.Range("$G$1:$AP$400000").AutoFilter Field:=36
    Selection.AutoFilter
    On Error GoTo 0
Continue_Code14:
    End With

As you can see from image, the values are being sorted properly, but they are not being removed.
 

Attachments

  • sort.png
    sort.png
    48.6 KB · Views: 15
Perhaps you can provide a sample of your data using the XL2BB add in so I can determine why it isn't working for you? When I run the code on what I assume is your sheet layout, it goes from this:
concat.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAP
1hdr1hdr2hdr3hdr4hdr5hdr6hdr7hdr8hdr9hdr10hdr11hdr12hdr13hdr14hdr15hdr16hdr17hdr18hdr19hdr20hdr21hdr22hdr23hdr24hdr25hdr26hdr27hdr28hdr29hdr30hdr31hdr32hdr33hdr34hdr35hdr36hdr37hdr38hdr39hdr40hdr41hdr42
2222222222222222222222222222222222222222221.8
3333333333333333333333333333333333333333330.1
4444444444444444444444444444444444444444440.7
5555555555555555555555555555555555555555551.2
6666666666666666666666666666666666666666661.5
7777777777777777777777777777777777777777771.9
8888888888888888888888888888888888888888880.2
9999999999999999999999999999999999999999990.2
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101.8
1111111111111111111111111111111111111111111111111111111111111111111111111111111111110.9
1212121212121212121212121212121212121212121212121212121212121212121212121212121212121.3
1313131313131313131313131313131313131313131313131313131313131313131313131313131313130.7
1414141414141414141414141414141414141414141414141414141414141414141414141414141414141.5
1515151515151515151515151515151515151515151515151515151515151515151515151515151515150.7
1616161616161616161616161616161616161616161616161616161616161616161616161616161616161.6
1717171717171717171717171717171717171717171717171717171717171717171717171717171717170.6
1818181818181818181818181818181818181818181818181818181818181818181818181818181818180.3
1919191919191919191919191919191919191919191919191919191919191919191919191919191919190.7
2020202020202020202020202020202020202020202020202020202020202020202020202020202020201.5
2121212121212121212121212121212121212121212121212121212121212121212121212121212121211.0
2222222222222222222222222222222222222222222222222222222222222222222222222222222222221.0
2323232323232323232323232323232323232323232323232323232323232323232323232323232323231.2
2424242424242424242424242424242424242424242424242424242424242424242424242424242424240.2
2525252525252525252525252525252525252525252525252525252525252525252525252525252525252.0
2626262626262626262626262626262626262626262626262626262626262626262626262626262626261.2
2727272727272727272727272727272727272727272727272727272727272727272727272727272727270.7
2828282828282828282828282828282828282828282828282828282828282828282828282828282828280.3
2929292929292929292929292929292929292929292929292929292929292929292929292929292929290.3
3030303030303030303030303030303030303030303030303030303030303030303030303030303030300.4
3131313131313131313131313131313131313131313131313131313131313131313131313131313131311.5
3232323232323232323232323232323232323232323232323232323232323232323232323232323232321.4
3333333333333333333333333333333333333333333333333333333333333333333333333333333333330.3
3434343434343434343434343434343434343434343434343434343434343434343434343434343434341.4
3535353535353535353535353535353535353535353535353535353535353535353535353535353535350.2
3636363636363636363636363636363636363636363636363636363636363636363636363636363636361.2
3737373737373737373737373737373737373737373737373737373737373737373737373737373737371.2
3838383838383838383838383838383838383838383838383838383838383838383838383838383838380.5
3939393939393939393939393939393939393939393939393939393939393939393939393939393939391.5
4040404040404040404040404040404040404040404040404040404040404040404040404040404040401.7
4141414141414141414141414141414141414141414141414141414141414141414141414141414141411.7
4242424242424242424242424242424242424242424242424242424242424242424242424242424242421.1
4343434343434343434343434343434343434343434343434343434343434343434343434343434343431.3
4444444444444444444444444444444444444444444444444444444444444444444444444444444444441.7
4545454545454545454545454545454545454545454545454545454545454545454545454545454545450.9
4646464646464646464646464646464646464646464646464646464646464646464646464646464646461.1
4747474747474747474747474747474747474747474747474747474747474747474747474747474747471.3
4848484848484848484848484848484848484848484848484848484848484848484848484848484848481.4
4949494949494949494949494949494949494949494949494949494949494949494949494949494949491.9
5050505050505050505050505050505050505050505050505050505050505050505050505050505050501.7
5151515151515151515151515151515151515151515151515151515151515151515151515151515151510.4
5252525252525252525252525252525252525252525252525252525252525252525252525252525252520.0
5353535353535353535353535353535353535353535353535353535353535353535353535353535353530.1
5454545454545454545454545454545454545454545454545454545454545454545454545454545454540.2
5555555555555555555555555555555555555555555555555555555555555555555555555555555555551.1
5656565656565656565656565656565656565656565656565656565656565656565656565656565656561.7
5757575757575757575757575757575757575757575757575757575757575757575757575757575757571.7
5858585858585858585858585858585858585858585858585858585858585858585858585858585858580.9
5959595959595959595959595959595959595959595959595959595959595959595959595959595959590.3
6060606060606060606060606060606060606060606060606060606060606060606060606060606060601.0
6161616161616161616161616161616161616161616161616161616161616161616161616161616161610.5
6262626262626262626262626262626262626262626262626262626262626262626262626262626262621.5
6363636363636363636363636363636363636363636363636363636363636363636363636363636363631.3
6464646464646464646464646464646464646464646464646464646464646464646464646464646464641.4
6565656565656565656565656565656565656565656565656565656565656565656565656565656565650.3
6666666666666666666666666666666666666666666666666666666666666666666666666666666666661.3
6767676767676767676767676767676767676767676767676767676767676767676767676767676767671.3
6868686868686868686868686868686868686868686868686868686868686868686868686868686868681.1
6969696969696969696969696969696969696969696969696969696969696969696969696969696969690.6
7070707070707070707070707070707070707070707070707070707070707070707070707070707070701.6
Sheet2


To this:
concat.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAP
1hdr1hdr2hdr3hdr4hdr5hdr6hdr7hdr8hdr9hdr10hdr11hdr12hdr13hdr14hdr15hdr16hdr17hdr18hdr19hdr20hdr21hdr22hdr23hdr24hdr25hdr26hdr27hdr28hdr29hdr30hdr31hdr32hdr33hdr34hdr35hdr36hdr37hdr38hdr39hdr40hdr41hdr42
2222222222222222222222222222222222222222221.8
3555555555555555555555555555555555555555551.2
4666666666666666666666666666666666666666661.5
5777777777777777777777777777777777777777771.9
610101010101010101010101010101010101010101010101010101010101010101010101010101010101.8
712121212121212121212121212121212121212121212121212121212121212121212121212121212121.3
814141414141414141414141414141414141414141414141414141414141414141414141414141414141.5
916161616161616161616161616161616161616161616161616161616161616161616161616161616161.6
1020202020202020202020202020202020202020202020202020202020202020202020202020202020201.5
1122222222222222222222222222222222222222222222222222222222222222222222222222222222221.0
1223232323232323232323232323232323232323232323232323232323232323232323232323232323231.2
1325252525252525252525252525252525252525252525252525252525252525252525252525252525252.0
1426262626262626262626262626262626262626262626262626262626262626262626262626262626261.2
1531313131313131313131313131313131313131313131313131313131313131313131313131313131311.5
1632323232323232323232323232323232323232323232323232323232323232323232323232323232321.4
1734343434343434343434343434343434343434343434343434343434343434343434343434343434341.4
1836363636363636363636363636363636363636363636363636363636363636363636363636363636361.2
1937373737373737373737373737373737373737373737373737373737373737373737373737373737371.2
2039393939393939393939393939393939393939393939393939393939393939393939393939393939391.5
2140404040404040404040404040404040404040404040404040404040404040404040404040404040401.7
2241414141414141414141414141414141414141414141414141414141414141414141414141414141411.7
2342424242424242424242424242424242424242424242424242424242424242424242424242424242421.1
2443434343434343434343434343434343434343434343434343434343434343434343434343434343431.3
2544444444444444444444444444444444444444444444444444444444444444444444444444444444441.7
2646464646464646464646464646464646464646464646464646464646464646464646464646464646461.1
2747474747474747474747474747474747474747474747474747474747474747474747474747474747471.3
2848484848484848484848484848484848484848484848484848484848484848484848484848484848481.4
2949494949494949494949494949494949494949494949494949494949494949494949494949494949491.9
3050505050505050505050505050505050505050505050505050505050505050505050505050505050501.7
3155555555555555555555555555555555555555555555555555555555555555555555555555555555551.1
3256565656565656565656565656565656565656565656565656565656565656565656565656565656561.7
3357575757575757575757575757575757575757575757575757575757575757575757575757575757571.7
3462626262626262626262626262626262626262626262626262626262626262626262626262626262621.5
3563636363636363636363636363636363636363636363636363636363636363636363636363636363631.3
3664646464646464646464646464646464646464646464646464646464646464646464646464646464641.4
3766666666666666666666666666666666666666666666666666666666666666666666666666666666661.3
3867676767676767676767676767676767676767676767676767676767676767676767676767676767671.3
3968686868686868686868686868686868686868686868686868686868686868686868686868686868681.1
4070707070707070707070707070707070707070707070707070707070707070707070707070707070701.6
Sheet2


As you can see, the cells in columns A:E are untouched, and the headers are not deleted.
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I'll try getting something attached here in a few minutes. Was having issues with excel blocking xl2bb
 
Upvote 0
disregard2NewestMonTest(DONOTUSE)4.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAP
1QBFLEXFLEXFLEXFLEXQBFLEXFLEXFLEXFLEXComboIDΣ SalaryΣ ProjectionΣ ProbabilityΣ TargetΣ DepthΣ #RestrictionΣ Ceiling ValueΣ ValueΣ StackΣ Stack POSΣ CommasΣ FilterΣ Player1Σ Player2QBFLEXFLEXFLEXFLEXQBFLEXFLEXFLEXFLEXQBFLEXFLEXFLEXFLEXΣ MVP
2Justin HerbertJustin HerbertJustin HerbertJustin HerbertZack MossKeenan AllenJustin HerbertDeon JacksonChase McLaughlinIndianapolis Colts664635850065.525153.1860.46531.3006837611.120085INDFLEX,FLEX,FLEX3027.6826.3135.8624.3223.6813.6618.397.3813.027.95WRQBRBKD0
3Austin EkelerAustin EkelerAustin EkelerAustin EkelerChase McLaughlinMike WilliamsJustin HerbertDeon JacksonChase McLaughlinIndianapolis Colts1311435750064.985156.85559.41631.3970434781.130173INDFLEX,FLEX,FLEX3030.2726.3135.8624.3223.6812.7918.397.3813.027.95WRQBRBKD0
4Keenan AllenKeenan AllenKeenan AllenKeenan AllenCameron DickerJustin HerbertKeenan AllenDeon JacksonChase McLaughlinIndianapolis Colts110235850069.425152.98560.46531.3006837611.186752INDFLEX,FLEX,FLEX3026.3127.6835.8624.3223.6818.3913.667.3813.027.95QBWRRBKD0
5Nick FolesNick FolesNick FolesNick FolesGerald EverettJustin HerbertMike WilliamsDeon JacksonChase McLaughlinIndianapolis Colts202635750069.065155.43559.41631.3970434781.20113INDFLEX,FLEX,FLEX3026.3130.2735.8624.3223.6818.3912.797.3813.027.95QBWRRBKD0
6Mike WilliamsMike WilliamsMike WilliamsMike WilliamsJoshua PalmerMike WilliamsKeenan AllenDeon JacksonChase McLaughlinIndianapolis Colts1403835500057.185157.24554.82631.3336363641.039727INDFLEX,FLEX,FLEX3030.2727.6835.8624.3223.6812.7913.667.3813.027.95WRWRRBKD0
7Deon JacksonDeon JacksonDeon JacksonDeon JacksonParris CampbellKeenan AllenMike WilliamsDeon JacksonChase McLaughlinIndianapolis Colts849435500057.365156.0254.82631.3336363641.043INDFLEX,FLEX,FLEX3027.6830.2735.8624.3223.6813.6612.797.3813.027.95WRWRRBKD0
8Michael Pittman Jr.Michael Pittman Jr.Michael Pittman Jr.Michael Pittman Jr.Alec PierceJustin HerbertDeon JacksonChase McLaughlinParris CampbellIndianapolis Colts259335400062.105150.82558.06631.3979629631.150092INDFLEX,FLEX,FLEX,FLEX4026.3135.8624.3225.4123.6818.397.3813.0211.317.95QBRBKWRD0
9Zack MossZack MossJoshua KelleyJustin HerbertDeon JacksonMichael Pittman Jr.Chase McLaughlinIndianapolis Colts252135800066.925159.40557.54531.311379311.153879INDFLEX,FLEX,FLEX,FLEX4026.3135.8635.1224.3223.6818.397.3810.6613.027.95QBRBWRKD0
10Chase McLaughlinChase McLaughlinDeAndre CarterKeenan AllenJustin HerbertDeon JacksonParris CampbellIndianapolis Colts665235800061.495154.0258.7631.2953448281.060258INDFLEX,FLEX,FLEX3027.6826.3135.8625.4123.6813.6618.397.3811.317.95WRQBRBWRD0
11Cameron DickerCameron DickerDonald Parham Jr.Mike WilliamsJustin HerbertDeon JacksonParris CampbellIndianapolis Colts1312035700060.955157.69557.65731.392456141.069385INDFLEX,FLEX,FLEX3030.2726.3135.8625.4123.6812.7918.397.3811.317.95WRQBRBWRD0
12Gerald EverettGerald EverettJelani WoodsKeenan AllenJustin HerbertDeon JacksonAlec PierceIndianapolis Colts665385700061.115151.4858.17731.2717543861.072192INDFLEX,FLEX,FLEX3027.6826.3135.8622.3123.6813.6618.397.3810.757.95WRQBRBWRD0
13Joshua PalmerJoshua PalmerLos Angeles ChargersMike WilliamsJustin HerbertDeon JacksonAlec PierceIndianapolis Colts1312185600060.575155.15557.12831.3701785711.081696INDFLEX,FLEX,FLEX3030.2726.3135.8622.3123.6812.7918.397.3810.757.95WRQBRBWRD0
14Parris CampbellParris CampbellIndianapolis ColtsJustin HerbertKeenan AllenDeon JacksonParris CampbellIndianapolis Colts110835800065.395153.82558.7631.2953448281.1275INDFLEX,FLEX,FLEX3026.3127.6835.8625.4123.6818.3913.667.3811.317.95QBWRRBWRD0
15Alec PierceAlec PierceAshton DulinJustin HerbertKeenan AllenDeon JacksonAlec PierceIndianapolis Colts110985700065.015151.28558.17731.2717543861.140614INDFLEX,FLEX,FLEX3026.3127.6835.8622.3123.6818.3913.667.3810.757.95QBWRRBWRD0
16Joshua KelleyJordan WilkinsJustin HerbertMike WilliamsDeon JacksonParris CampbellIndianapolis Colts203235700065.035156.27557.65731.392456141.140964INDFLEX,FLEX,FLEX3026.3130.2735.8625.4123.6818.3912.797.3811.317.95QBWRRBWRD0
17DeAndre CarterJustin HerbertMike WilliamsDeon JacksonAlec PierceIndianapolis Colts203385600064.655153.73557.12831.3701785711.154553INDFLEX,FLEX,FLEX3026.3130.2735.8622.3123.6818.3912.797.3810.757.95QBWRRBWRD0
18Donald Parham Jr.Keenan AllenDeon JacksonMichael Pittman Jr.Chase McLaughlinIndianapolis Colts898935550055.225159.9952.95531.2446846850.995045INDFLEX,FLEX,FLEX,FLEX4027.6835.8635.1224.3223.6813.667.3810.6613.027.95WRRBWRKD0
19Jelani WoodsMike WilliamsDeon JacksonMichael Pittman Jr.Chase McLaughlinIndianapolis Colts1545735450054.685163.66551.9631.3453211011.003394INDFLEX,FLEX,FLEX,FLEX4030.2735.8635.1224.3223.6812.797.3810.6613.027.95WRRBWRKD0
20Los Angeles ChargersMike WilliamsKeenan AllenDeon JacksonParris CampbellIndianapolis Colts1404435450053.155158.08553.06731.3282568810.975321INDFLEX,FLEX,FLEX3030.2727.6835.8625.4123.6812.7913.667.3811.317.95WRWRRBWRD0
21Indianapolis ColtsKeenan AllenMike WilliamsDeon JacksonParris CampbellIndianapolis Colts850035450053.335156.8653.06731.3282568810.978623INDFLEX,FLEX,FLEX3027.6830.2735.8625.4123.6813.6612.797.3811.317.95WRWRRBWRD0
22Ashton DulinMike WilliamsKeenan AllenDeon JacksonMichael Pittman Jr.Indianapolis Colts1403535850057.975166.66552.54631.2471794870.991025INDFLEX,FLEX,FLEX3030.2727.6835.8635.1223.6812.7913.667.3810.667.95WRWRRBWRD0
23Jordan WilkinsKeenan AllenMike WilliamsDeon JacksonMichael Pittman Jr.Indianapolis Colts849135850058.155165.4452.54631.2471794870.994102INDFLEX,FLEX,FLEX3027.6830.2735.8635.1223.6813.6612.797.3810.667.95WRWRRBWRD1
24Justin HerbertDeon JacksonMichael Pittman Jr.Parris CampbellIndianapolis Colts252735750062.895160.24555.78631.3060869571.093826INDFLEX,FLEX,FLEX,FLEX4026.3135.8635.1225.4123.6818.397.3810.6611.317.95QBRBWRWRD1
25Justin HerbertDeon JacksonMichael Pittman Jr.Alec PierceIndianapolis Colts252885650062.515157.70555.25731.2824778761.10646INDFLEX,FLEX,FLEX,FLEX4026.3135.8635.1222.3123.6818.397.3810.6610.757.95QBRBWRWRD1
26Keenan AllenDeon JacksonMichael Pittman Jr.Parris CampbellIndianapolis Colts899535500051.195160.8351.19631.2385454550.930818INDFLEX,FLEX,FLEX,FLEX4027.6835.8635.1225.4123.6813.667.3810.6611.317.95WRRBWRWRD1
27Mike WilliamsDeon JacksonMichael Pittman Jr.Parris CampbellIndianapolis Colts1546335400050.655164.50550.14731.340.938055INDFLEX,FLEX,FLEX,FLEX4030.2735.8635.1225.4123.6812.797.3810.6611.317.95WRRBWRWRD1
28Keenan AllenDeon JacksonMichael Pittman Jr.Alec PierceIndianapolis Colts899685400050.815158.2950.66731.2125925930.941018INDFLEX,FLEX,FLEX,FLEX4027.6835.8635.1222.3123.6813.667.3810.6610.757.95WRRBWRWRD1
29Keenan AllenAustin EkelerDeon JacksonChase McLaughlinIndianapolis Colts710835900062.375155.8872.97531.3740677971.057203INDFLEX,FLEX,FLEX3027.6829.8635.8624.3223.6813.6630.857.3813.027.95WRRBRBKD1
30Mike WilliamsAustin EkelerDeon JacksonChase McLaughlinIndianapolis Colts1357635800061.835159.55571.92631.4708620691.06612INDFLEX,FLEX,FLEX3030.2729.8635.8624.3223.6812.7930.857.3813.027.95WRRBRBKD1
31Austin EkelerKeenan AllenDeon JacksonChase McLaughlinIndianapolis Colts433635900064.7157.03572.97531.3740677971.09661INDFLEX,FLEX,FLEX3029.8627.6835.8624.3223.6830.8513.667.3813.027.95RBWRRBKD1
32Austin EkelerMike WilliamsDeon JacksonChase McLaughlinIndianapolis Colts526035800064.34159.48571.92631.4708620691.10931INDFLEX,FLEX,FLEX3029.8630.2735.8624.3223.6830.8512.797.3813.027.95RBWRRBKD1
33Austin EkelerJustin HerbertDeon JacksonAlec PierceIndianapolis Colts341986000068.09154.94575.27731.40751.134833INDFLEX,FLEX,FLEX3029.8626.3135.8622.3123.6830.8518.397.3810.757.95RBQBRBWRD1
34Justin HerbertAustin EkelerDeon JacksonAlec PierceIndianapolis Colts64786000069.665153.59575.27731.40751.161083INDFLEX,FLEX,FLEX3026.3129.8635.8622.3123.6818.3930.857.3810.757.95QBRBRBWRD1
35Austin EkelerDeon JacksonChase McLaughlinParris CampbellIndianapolis Colts582735450057.38154.87570.57631.4765137611.052844INDFLEX,FLEX,FLEX,FLEX4029.8635.8624.3225.4123.6830.857.3813.0211.317.95RBRBKWRD1
36Austin EkelerDeon JacksonMichael Pittman Jr.Chase McLaughlinIndianapolis Colts575535850062.2163.45570.05531.3852991451.063247INDFLEX,FLEX,FLEX,FLEX4029.8635.8635.1224.3223.6830.857.3810.6613.027.95RBRBWRKD1
37Keenan AllenAustin EkelerDeon JacksonParris CampbellIndianapolis Colts711435850058.345156.7271.21631.3694017090.99735INDFLEX,FLEX,FLEX3027.6829.8635.8625.4123.6813.6630.857.3811.317.95WRRBRBWRD1
38Mike WilliamsAustin EkelerDeon JacksonParris CampbellIndianapolis Colts1358235750057.805160.39570.16731.4669565221.005304INDFLEX,FLEX,FLEX3030.2729.8635.8625.4123.6812.7930.857.3811.317.95WRRBRBWRD1
39Keenan AllenAustin EkelerDeon JacksonAlec PierceIndianapolis Colts711585750057.965154.1870.68731.3473043481.008086INDFLEX,FLEX,FLEX3027.6829.8635.8622.3123.6813.6630.857.3810.757.95WRRBRBWRD1
40Mike WilliamsAustin EkelerDeon JacksonAlec PierceIndianapolis Colts1358385650057.425157.85569.63831.446194691.016371INDFLEX,FLEX,FLEX3030.2729.8635.8622.3123.6812.7930.857.3810.757.95WRRBRBWRD1
Worksheet
Cell Formulas
RangeFormula
X2:X40X2=IF($Z$2="",COUNTIF(G2:K2,$Y$2),COUNTIF(G2:K2,$Y$2)*COUNTIF(G2:K2,$Z$2))
 
Upvote 0
Try this:
VBA Code:
Option Explicit
Sub DeleteOnAP_V3()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet2")   '<~~ ** Change this to actual sheet name **
    Dim r As Range
    Set r = Intersect(ws.UsedRange, ws.Range("G:AP"))
    r.Select
    
    With r
        .AutoFilter 36, "<1"
        If r.Cells(Rows.Count, 36).End(xlUp).Row > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).Value2 = ""
            .AutoFilter
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(4).Delete shift:=xlUp
        Else
            .AutoFilter
        End If
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try this:
VBA Code:
Option Explicit
Sub DeleteOnAP_V3()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet2")   '<~~ ** Change this to actual sheet name **
    Dim r As Range
    Set r = Intersect(ws.UsedRange, ws.Range("G:AP"))
    r.Select
   
    With r
        .AutoFilter 36, "<1"
        If r.Cells(Rows.Count, 36).End(xlUp).Row > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).Value2 = ""
            .AutoFilter
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(4).Delete shift:=xlUp
        Else
            .AutoFilter
        End If
    End With
    Application.ScreenUpdating = True
End Sub
Awesome kevin! That worked! Mind explaining how that worked? hah thanks so much!
 
Upvote 0
Awesome kevin! That worked! Mind explaining how that worked? hah thanks so much!
Once the filter was applied, it filled every visible cell in the range G:AP (from row 2 down) with a blank ("") and then selected SpecialCells(4) (= blank cells) and deleted the cells - shifting up after deletion. The test as to whether any rows were found with the filter <1 in column AP was: "If r.Cells(Rows.Count, 36).End(xlUp).Row > 1 Then" which asks if, after selecting the last cell in the column & using the End(xlUp) command - did it go to row 1 (which means that no values were found in the filter) so if it went to a row greater than 1 ( If.....> 1 Then) then execute the code within the If statement - otherwise (Else), go straight to turning the Autofilter off. I hope that helps.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

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