Delete based on cell value

cspengel

Board Regular
Joined
Oct 29, 2022
Messages
173
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I have tried so many different VBA code and it is not working. ANY code I try, it mixes up the rows or the data in general gets all jumbled up. I've tried autofilter, and loops..Nothing. Beyond Frustrating.

I NEED the rows to stay together. What I mean is G2-H2-I2-J2 etc. Some of the code i've tried is shifting the order for some reason.

I need ALL rows to be deleted that contain "1" in the column M.
I need ALL rows to be deleted that contain "0" in column R

My data looks as follows:

Showdown Slate1.xlsm
ABCDEFGHIJKLMNOPQRSTU
1QBFLEXFLEXFLEXFLEXQBFLEXFLEXFLEXFLEXComboIDΣ SalaryΣ ProjectionΣ ValueΣ StackΣ Stack POSΣ CommasΣ FilterΣ Player1Σ Player2
2Dak PrescottDak PrescottDak PrescottDak PrescottDak PrescottDak PrescottCeeDee LambTony PollardJonathan TaylorMatt Ryan2225183.38583385DALQB,FLEX,FLEX30
3CeeDee LambCeeDee LambCeeDee LambCeeDee LambCeeDee LambDak PrescottCeeDee LambTony PollardJonathan TaylorEzekiel Elliott2226183.29583295DALQB,FLEX,FLEX,FLEX00
4Tony PollardTony PollardTony PollardTony PollardTony PollardDak PrescottCeeDee LambTony PollardDalton SchultzBrett Maher2277176.38576385DALQB,FLEX,FLEX,FLEX,FLEX00
5Jonathan TaylorJonathan TaylorJonathan TaylorJonathan TaylorJonathan TaylorDak PrescottCeeDee LambTony PollardDalton SchultzMichael Gallup22786000075.7851.263083333DALQB,FLEX,FLEX,FLEX,FLEX00
6Matt RyanMatt RyanMatt RyanMatt RyanMatt RyanDak PrescottCeeDee LambTony PollardDalton SchultzChase McLaughlin22795950075.4751.268487395DALQB,FLEX,FLEX,FLEX00
7Ezekiel ElliottEzekiel ElliottEzekiel ElliottEzekiel ElliottEzekiel ElliottDak PrescottCeeDee LambTony PollardDalton SchultzDallas Cowboys2280174.67574675DALQB,FLEX,FLEX,FLEX,FLEX00
8Michael Pittman Jr.Michael Pittman Jr.Michael Pittman Jr.Michael Pittman Jr.Michael Pittman Jr.Dak PrescottCeeDee LambTony PollardJake FergusonChase McLaughlin2291169.63569635DALQB,FLEX,FLEX,FLEX00
9Alec PierceDalton SchultzDalton SchultzDak PrescottCeeDee LambTony PollardJake FergusonDallas Cowboys22925900068.8351.166694915DALQB,FLEX,FLEX,FLEX,FLEX00
10Indianapolis ColtsJake FergusonBrett MaherDak PrescottCeeDee LambTony PollardPeyton HendershotJonathan Taylor2296173.54573545DALQB,FLEX,FLEX,FLEX00
11Deon JacksonPeyton HendershotMichael GallupDak PrescottCeeDee LambTony PollardPeyton HendershotMatt Ryan2297172.97572975DALQB,FLEX,FLEX,FLEX00
12Jake FergusonKylen GransonChase McLaughlinDak PrescottCeeDee LambTony PollardKylen GransonDalton Schultz2312169.77569775DALQB,FLEX,FLEX,FLEX00
13Peyton HendershotJelani WoodsDallas CowboysDak PrescottCeeDee LambTony PollardKylen GransonBrett Maher23135900069.5851.17940678DALQB,FLEX,FLEX,FLEX00
14Mo Alie-CoxDak PrescottCeeDee LambTony PollardKylen GransonMichael Gallup2314168.98568985DALQB,FLEX,FLEX,FLEX00
15Dak PrescottCeeDee LambTony PollardKylen GransonChase McLaughlin2315168.67568675DALQB,FLEX,FLEX30
16Dak PrescottCeeDee LambTony PollardKylen GransonDallas Cowboys23165950067.8751.140756303DALQB,FLEX,FLEX,FLEX00
Worksheet
Cell Formulas
RangeFormula
S2:S16S2=IF($U$2="",COUNTIF(G2:K2,$T$2),COUNTIF(G2:K2,$T$2)*COUNTIF(G2:K2,$U$2))
 
Well that is why I only had the information I posted in #1 as the layout is the only thing that should be the problem. The current macro should not be affecting anything in regards to how this delete method operates. The other sheets also have no effect. Sorry if I sound foward, it is just difficult to explain the whole project and the macro itself takes long to run, and it isn't something that I can just post and you can copy it and run it quickly.


I have found some code that may be working for me.





VBA Code:
 LR = Range("G" & Rows.Count).End(xlUp).Row
Set c = Intersect(ActiveSheet.UsedRange, Range("M:M"))

Application.ScreenUpdating = False
c.Replace what:="1", replacement:="#N/A", lookat:=xlWhole
On Error Resume Next
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Add2 Key:=Range( _
        "M2:M400000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Worksheet").Sort
        .SetRange Range("G1:U400000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("M1").CurrentRegion.Select
    With Selection
    ActiveSheet.Range("$G$1:$U$400000").AutoFilter Field:=7, Criteria1:="#N/A"
    .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    ActiveSheet.Range("$G$1:$U$400000").AutoFilter Field:=7
    Selection.AutoFilter
On Error GoTo 0
End With

My issue I believe was with selecting the contents after the filter. So after I filter M by "1" How to select ALL of the filtered only contents and delete.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Well that is why I only had the information I posted in #1 as the layout is the only thing that should be the problem. The current macro should not be affecting anything in regards to how this delete method operates. The other sheets also have no effect. Sorry if I sound foward, it is just difficult to explain the whole project and the macro itself takes long to run, and it isn't something that I can just post and you can copy it and run it quickly.


I have found some code that may be working for me.





VBA Code:
 LR = Range("G" & Rows.Count).End(xlUp).Row
Set c = Intersect(ActiveSheet.UsedRange, Range("M:M"))

Application.ScreenUpdating = False
c.Replace what:="1", replacement:="#N/A", lookat:=xlWhole
On Error Resume Next
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Worksheet").Sort.SortFields.Add2 Key:=Range( _
        "M2:M400000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Worksheet").Sort
        .SetRange Range("G1:U400000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("M1").CurrentRegion.Select
    With Selection
    ActiveSheet.Range("$G$1:$U$400000").AutoFilter Field:=7, Criteria1:="#N/A"
    .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    ActiveSheet.Range("$G$1:$U$400000").AutoFilter Field:=7
    Selection.AutoFilter
On Error GoTo 0
End With

My issue I believe was with selecting the contents after the filter. So after I filter M by "1" How to select ALL of the filtered only contents and delete.
I think I got it 👍 thanks for your help!
 
Upvote 0
Glad you seem to have something working. I was just fishing for all the information that I could get since the code in post 4 worked for the sample data that I had (from post 1) so something had to be different between our workbooks. :)
Anyway - all's well that ends well. (y)
 
Upvote 0

Forum statistics

Threads
1,215,161
Messages
6,123,371
Members
449,097
Latest member
thnirmitha

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