Need help with macro

henrybrent1974

New Member
Joined
Oct 11, 2017
Messages
19
I am defiantly new to macros. i have learned a lot from this forum but cant seem to figure out how to write this macro.
I am trying to take 3 player from each weekly results based on the previous week. For example, the first week the top 3 players would qualify. In the second week if any of the top 3 are the same as week #1 top 3 the take 4th place and so on. need this to continue for 30 weeks.

[TABLE="class: grid, width: 120"]
<tbody>[TR]
[TD][/TD]
[TD]Week #1
[/TD]
[/TR]
[TR]
[TD]1st
[/TD]
[TD]Jason
[/TD]
[/TR]
[TR]
[TD]2nd
[/TD]
[TD]Troy
[/TD]
[/TR]
[TR]
[TD]3rd
[/TD]
[TD]Mike
[/TD]
[/TR]
[TR]
[TD]4th
[/TD]
[TD]Ricky
[/TD]
[/TR]
[TR]
[TD]5th
[/TD]
[TD]John
[/TD]
[/TR]
[TR]
[TD]6th
[/TD]
[TD]Mark
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 120"]
<tbody>[TR]
[TD][/TD]
[TD]Week #2
[/TD]
[/TR]
[TR]
[TD]1st
[/TD]
[TD]Mike
[/TD]
[/TR]
[TR]
[TD]2nd
[/TD]
[TD]Joe
[/TD]
[/TR]
[TR]
[TD]3rd
[/TD]
[TD]Jake
[/TD]
[/TR]
[TR]
[TD]4th
[/TD]
[TD]Jason
[/TD]
[/TR]
[TR]
[TD]5th
[/TD]
[TD]Bubba
[/TD]
[/TR]
[TR]
[TD]6th
[/TD]
[TD]Trey
[/TD]
[/TR]
</tbody>[/TABLE]

So my qualifiers so for would be:
1. Jason
2. Troy
3. Mike
4. Joe
5. Jake
6. Bubba

Any help would be appreciated so much
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the MrExcel board!

Assuming the layout is as shown below (including a blank row between each week), try this in a copy of your workbook.

Rich (BB code):
Sub Get_Qualifiers()
  Dim d As Object
  Dim rA As Range
  Dim Got As Long, r As Long
  
  Const NumPerWeek As Long = 3  '<- How many to pick from each week
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  For Each rA In Range("B1", Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
    Got = 0
    r = 1
    Do
      r = r + 1
      If Not d.exists(rA.Cells(r).Value) Then
        d(rA.Cells(r).Value) = 1
        Got = Got + 1
      End If
    Loop Until Got = NumPerWeek Or r = rA.Rows.Count
  Next rA
  With Range("D1")
    .Value = "Qualifiers"
    .Offset(1).Resize(d.Count).Value = Application.Transpose(d.keys)
    .EntireColumn.AutoFit
  End With
End Sub

My sample data and results are below.
Note that only two qualifiers were added from week 3 because all the rest had already qualified. Is that what you want?


Book1
ABCD
1Week#1Qualifiers
21stJasonJason
32ndTroyTroy
43rdMikeMike
54thRickyJoe
65thJohnJake
76thMarkBubba
8Sam
9Week#2Jim
101stMikeJen
112ndJoeAnn
123rdJakeSue
134thJason
145thBubba
156thTrey
16
17Week#3
181stMike
192ndSam
203rdJoe
214thJason
225thJim
236thTroy
24
25Week#4
261stJen
272ndSam
283rdAnn
294thJason
305thSue
316thTroy
Qualifiers
 
Upvote 0
Thanks for the help. My weekly data is arranged week 1 thru week 5 from left to right then skip a row and week 6 thru week 10 right below and so forth. Sorry for putting my sample going down. i couldn't figure out how to make a table next to the other one.
 
Upvote 0
For example if 1st, 2nd and 3rd are already qualified then i only need 5th and 6th.
In that example, wouldn't you need 4th, 5th and 6th?
For the sample data I posted previously, were my results correct, particularly noting the comment just above the screen shot about week 3?


I have attached a link to a picture of the way I have my spreadsheet arranged.
That is useful to know but I cannot copy from that and there is too much to be bothered typing out to test. Could you post the sample in this thread using one of the tools linked in my signature block below? Then I can copy/paste the sample data. :)
 
Upvote 0
Yes you are correct and yes the code worked until it got to where if 4 of the 6 places were already qualified. Then it would give me the blank cell below the 6th place or the week# for the next week.
here the my data like you asked. Thanks again.


Book1
NOPQRSTUVWXYZAAABAC
1
2WEEK #1WEEK #2WEEK #3WEEK #4WEEK #5
31stDAVE1stKANE1stROBBY1stCALVIN1stROBBY
42ndDREW2ndRICKY D2ndBRENT G2ndSTEVE T2ndRYAN
53rdKANE3rdBRAD3rdMIKE H3rdKANE3rdCALVIN
64thTRAVIS4thMOOSE4thJOSH4thJONATHAN4thMIKE B
75thDAVID5thBRANDON5thCAROL5thMOOSE5thSTEVE T
86thRICKY L6thMARK6thDONALD6thALTON6thJONATHAN
9
10WEEK #6WEEK #7WEEK #8WEEK #9WEEK #10
111stDAVE1stTROY1stROBBY1stBRENT A1stDAVE
122ndJASON R2ndRICKY D2ndTROY2ndROBBY2ndTROY
133rdTROY3rdDAVE3rdALLEN3rdJIMMY3rdTOBY
144thBRENT A4thROBBY4thNICK4thJASON L4thMARK L
155thDAVID5thCORY5thCURTIS JR5thRICKY D5thFRANKIE
166thROBBY6thMIKE B6th****6thSTEVE T6thMOOSE
17
18WEEK #11WEEK #12WEEK #13WEEK #14WEEK #15
191stMOOSE1st1st1st1st
202ndTRAVIS2nd2nd2nd2nd
213rdBRENT A3rd3rd3rd3rd
224thROBBY4th4th4th4th
235thFLOYD5th5th5th5th
246thTROY6th6th6th6th
25
Summary
 
Upvote 0
Thanks for the data (I should have asked for the expected results too. :)). Anyway here is my attempt. The colours below were applied manually & for my own benefit for checking. Each week heading has a colour (I'm not sure how distinguishable they will be in the forum when I post this) and the qualifiers from that week are given the same colour below and in column AE. If a person has already qualified from a previous week I have coloured them with the colour from the week they qualified (eg Kane in Week 2 and Week 4 is yellow because he qualified in Week 1). Only 2 people qualified from Week 5 because all the others had previously qualified.

Code:
Sub Get_Qualifiers_v2()
  Dim d As Object
  Dim rA As Range
  Dim Got As Long, r As Long
  
  Const NumPerWeek As Long = 3  '<- How many to pick from each week
  Const WeeksAcross As Long = 5 '<- How many weeks across the sheet in each set of rows
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  For Each rA In Range("O2", Range("O" & Rows.Count).End(xlUp)).Resize(, 3 * WeeksAcross - 1).SpecialCells(xlConstants).Areas
    If rA.Rows.Count > 1 Then
      Got = 0
      r = 0
      Do
        r = r + 1
        If Not d.exists(rA.Cells(r, 2).Value) Then
          d(rA.Cells(r, 2).Value) = 1
          Got = Got + 1
        End If
      Loop Until Got = NumPerWeek Or r = rA.Rows.Count
    End If
  Next rA
  With Range("AE1")
    .Value = "Qualifiers"
    .Offset(1).Resize(d.Count).Value = Application.Transpose(d.keys)
    .EntireColumn.AutoFit
  End With
End Sub


Book1
OPQRSTUVWXYZAAABACADAE
1Qualifiers
2WEEK #1WEEK #2WEEK #3WEEK #4WEEK #5DAVE
31stDAVE1stKANE1stROBBY1stCALVIN1stROBBYDREW
42ndDREW2ndRICKY D2ndBRENT G2ndSTEVE T2ndRYANKANE
53rdKANE3rdBRAD3rdMIKE H3rdKANE3rdCALVINRICKY D
64thTRAVIS4thMOOSE4thJOSH4thJONATHAN4thMIKE BBRAD
75thDAVID5thBRANDON5thCAROL5thMOOSE5thSTEVE TMOOSE
86thRICKY L6thMARK6thDONALD6thALTON6thJONATHANROBBY
9BRENT G
10WEEK #6WEEK #7WEEK #8WEEK #9WEEK #10MIKE H
111stDAVE1stTROY1stROBBY1stBRENT A1stDAVECALVIN
122ndJASON R2ndRICKY D2ndTROY2ndROBBY2ndTROYSTEVE T
133rdTROY3rdDAVE3rdALLEN3rdJIMMY3rdTOBYJONATHAN
144thBRENT A4thROBBY4thNICK4thJASON L4thMARK LRYAN
155thDAVID5thCORY5thCURTIS JR5thRICKY D5thFRANKIEMIKE B
166thROBBY6thMIKE B6th****6thSTEVE T6thMOOSEJASON R
17TROY
18WEEK #11WEEK #12WEEK #13WEEK #14WEEK #15BRENT A
191stMOOSE1st1st1st1stCORY
202ndTRAVIS2nd2nd2nd2ndALLEN
213rdBRENT A3rd3rd3rd3rdNICK
224thROBBY4th4th4th4thCURTIS JR
235thFLOYD5th5th5th5thJIMMY
246thTROY6th6th6th6thJASON L
25TOBY
26MARK L
27FRANKIE
28TRAVIS
29FLOYD
30
Qualifiers
 
Upvote 0
Something I have notice that I would need to happen also. If for any week that 5th place would qualify then I would need it to take 6th place also since on a tournament bracket 5th/6th is considered a tie so if i have to take one as qualified then i need to take both. Thanks in advance for any help.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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