+ Reply to Thread
Results 1 to 14 of 14

Randomize teams button

  1. #1
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Randomize teams button

    Hi, I have the following code to randomize couples with a button.

    However, there are two issues with this VBA code:
    1st issue: You have to manually select the range before the button macro can be applied. Is there a way to automatically selecting the range(s) of the teams in the code?
    2nd issue: Is it possible to randomize in such a way that e.g. Team I & Q get randomized together in the second range, let's say on fixed position 16 instead of only on the positions 1-10?

    I've attached the file. Thanks


    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Randomize teams button

    Can you explain from first principles what you want to achieve and manually add a couple of end results.

    It may be possible to do this with functions rather than macros. I find it difficult to understand your end goal from the explanation you've given so far.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Randomize teams button

    Sure. So, I have 20 couples for a tournament. The columns are positioned as seen in the attached image in order to fit on a printed page.
    The names of team member 1 and team member 2 have to be manually entered (on the image they are just letters).

    My goal is twofold:
    1) Shuffle merged cells BC2:BC11 (team member 1) as a pair with merged cells EF2:EF11 (team member 2) AND
    merged cells IJ2:IJ11 (team member 1) as a pair with merged cells LM2:LM11 (team member 2) randomly throughout the fixed positions 1-20.
    For example team I-Q (now on fixed position 1) gets randomly placed next to fixed position e.g. 18 or 9 or 11 or 4 ... The same goes for the other teams.
    This with a click on the randomize button.

    2) Before the randomize button is able to operate the macro, you first have to manually select the ranges. However, it would be a lot more user friendly if
    the button code already has the above mentioned ranges of team members selected so you only have to click the button without first having to manually select the ranges.

    I hope this is more clear. Thanks!
    Attached Images Attached Images

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Randomize teams button

    Hi,

    Are the merged cells of any importance? We generally advise against using merged cells since they cause too many problems?

    I'm still unclear as to what you expect to happen. Just highlighting cells A2:A11 as the note says simply randomises A2:A11 it doesn't affect any other columns. I'm assuming that you first select A2:E11, but even then only columns A&B change.

    Could you upload the workbook with a second sheet that shows what should have happened after randomising?
    Last edited by Richard Buttrey; 05-21-2017 at 10:23 AM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    Merged cells are not good at all.

    Try this one and see if this is how you wanted.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Randomize teams button

    I need the merged cells for printing purposes. As attached you can find a possible result of shuffling team entries on Excel Sheet2.

    I used colours to show that the team members should stay together when you hit the shuffle button. The fixed positions should stay in the same cell but not the teams assigned to those fixed positions (1 to 20).

    How can the VBA code on the shuffle button be altered so you do not have to highlight/select these ranges beforehand? The button should already know what the ranges to shuffle are.
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    How it is not working?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Randomize teams button

    Thanks, Jindon, this works very well. However, I do not understand the code that well to change the array.

    I applied this in another file (see attached) but it didn't work. Could you point out how to change the array?
    Attached Files Attached Files

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    Try
    Please Login or Register  to view this content.

    Edit:
    Found a bug so code has been fixed.
    Last edited by jindon; 05-21-2017 at 11:17 AM. Reason: Fixed a bug.

  10. #10
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Randomize teams button

    Hi Jindon, this does not work when you click several times on the button. In the end you get the same names in the entry cells.

    Also, when I write text in the row above the array, there are cells in that row that pop up entry names after hitting the button (thus outside of the range of entries).

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    Yep, I have just fixed a code, so copy and try again.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    Quote Originally Posted by Retroshift View Post
    Also, when I write text in the row above the array, there are cells in that row that pop up entry names after hitting the button (thus outside of the range of entries).
    Then change to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-01-2015
    Location
    Antwerp
    MS-Off Ver
    2019
    Posts
    71

    Re: Randomize teams button

    Thanks, Jindon. The code runs smoothly. You are a VBA wizzard!

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Randomize teams button

    You are welcome and thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Rating football teams/calculating superiority of football teams
    By gko_87 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-09-2017, 04:01 PM
  2. Randomize the teams
    By Quicksnot in forum Excel General
    Replies: 4
    Last Post: 07-22-2014, 11:22 AM
  3. [SOLVED] Two columns of teams, count the number of times the teams meet?
    By tpe102 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-04-2013, 09:21 AM
  4. 80 teams 25 weeks teams no dups over 25 weeks
    By hzppby in forum Excel General
    Replies: 0
    Last Post: 03-11-2013, 08:19 PM
  5. Randomize
    By Valkyrie1981 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2010, 11:27 AM
  6. Randomize
    By shaun0_0 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 09-12-2008, 02:24 PM
  7. Randomize
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-19-2008, 06:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1