+ Reply to Thread
Results 1 to 18 of 18

shuffled deck of cards

Hybrid View

  1. #1
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    I think the attached will do it.
    Row 1 is headers
    A2 is blank
    A3:A54 are the 52 cards "C 1","C 2", ..., "s 13"

    In B2, put
    =INT(RAND()*52)+1
    and fill right to BA2

    In B3, put
    =IF(ROWS($B$3:B3)=COLUMNS($B$3:B3),INDEX(A$3:A$54,B$2,1),IF(ROWS($B$3:B3)=B$2,INDEX(A$3:A$54,COLUMNS($B$3:B3),1),A3))
    Select B3:BA54, fill right and down.

    The column BA3:BA54 is the shuffled deck.

    What is happening is that, in the i'th column, a random number between 1-52 is being selected and the i'th card is being swapped with the random'th card.
    52 columns shuffles the whole deck.

    One could hide the 51 helper columns. This may be a case where VB is better than native Excel.
    Attached Files Attached Files
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  2. #2
    Registered User
    Join Date
    06-13-2007
    MS-Off Ver
    Office 365 (Version 2306)
    Posts
    78
    That's great!

    Can I push my luck and ask another question whilst I am at it?

    Is there a simple (ie non-VBA) way to get excel to work out what the first and second last characters in a cell are? Say I have "2 Black ducks" in A1 and "Johnny went to town" in A2, I would like the 1st character of A1 in B1 and the second last character of A1 in C1, likewise for what's in A2 to go into B2 and C2.

    Thanks again.
    Regards,

    David Obeid

    http://david.obeid.googlepages.com

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    If "Johnny went to town" is in A1,

    =LEFT(A1,1) returns the first character of A1, "J"

    =MID(A1,LEN(A1)-1,1) returns the second to last character of A1, "w"

    =RIGHT(A1,2) returns the last 2 characters of A1, "wn"

    The other text functions can be found through the Insert Function dialog box.

  4. #4
    Registered User
    Join Date
    06-13-2007
    MS-Off Ver
    Office 365 (Version 2306)
    Posts
    78
    Dynamite!

    This is a very helpful forum!

    Thanks a million!

  5. #5
    Registered User
    Join Date
    10-12-2018
    Location
    shrewsbury, England
    MS-Off Ver
    2013
    Posts
    6

    Re: shuffled deck of cards

    aaaaaaaaaaaaaaaaaaaaa
    Last edited by bevis; 10-12-2018 at 08:59 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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