3 Seasons only

nitebyfly

New Member
Joined
Mar 12, 2011
Messages
12
I have 21K rows of data where I need to delete entries under the following criteria;

delete those rows that only match one season OR
delete those rows that only match two seasons.

Keep those rows that where a name matches three seasons
(Fall, Jan(winter), Spring)

A B C
1 last first season
2 smith james fall
3 smith james jan(winter)
4 smith james spring
5 taylor john fall
6 taylor john spring
7 sand fresh fall

In this example the goal would be to delete or mark for deletion rows 5, 6 & 7.

Thank you for any help you can provide.

Tim
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
try this

Code:
Sub Seasons()
Dim LR As Long, i As Long
Dim Season As String
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
Season = Cells(i, 3)
Select Case Season
Case "fall"
    'keep row
Case Is = "spring"
    'keep row
Case Is = "jan(winter)"
    'keep row
Case Else
    Rows(i).EntireRow.Delete
End Select
Next
MsgBox "Done"
End Sub
 
Upvote 0
Thank you for your help. When I put your code in VBA and run it, it removes them all except for the heading. Could you possible look at it again?
Thanks so much.

Tim
 
Upvote 0
perhaps your data is not exactly those words? Had spaces or is not the same case (upper/lower) that would cause the rows to be deleted
 
Upvote 0
Thank you again for following this. I copied the example from my message, then Text to columns, inserted your code in vba, then ran it - and away it went deleting all but the heading row. It is true on the one I am planning on using it for, that the cases are different. If you wrote it for the example I gave, if it was going to work, wouldn't by copying it and setting it up in columns, without changing any case, then running your code be the test?

Again, my humble thanks.


Tim
 
Upvote 0
ok so before running by code i have

Excel Workbook
ABCD
1lastfirstseason1
2smithjamesfall2
3smithjamesjan(winter)3
4smithjamesspring4
5taylorjohnfall5
6taylorjohnspring6
7sandfreshfall7
8taylorjohnsummer8
9smithjamessummer9
10smithjamesFall10
11smithjamesSpring11
Sheet1

Excel 2003

after running code I have
Excel Workbook
ABCD
1lastfirstseason1
2smithjamesfall2
3smithjamesjan(winter)3
4smithjamesspring4
5taylorjohnfall5
6taylorjohnspring6
7sandfreshfall7
8smithjamesFall10
9smithjamesSpring11
Sheet1
Excel 2003
 
Upvote 0
Thank you for your trouble. I will give you some more background. This data is test data where students took an exam in the fall, then winter, then spring. The only students I want to look at are those that took all three, and delete the students that only took one or two of the three tests. So in my example, rows 5, 6, & 7 need to be deleted as they did not take 3 tests.
Does that help your analysis?

Tim
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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