+ Reply to Thread
Results 1 to 19 of 19

Shuffle data only of the 3 columns

  1. #1
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Shuffle data only of the 3 columns

    Using Excel 2010
    Hello,

    I need VBA to Random shuffle only 3 columns for example column D, column E, Column F as long as data find in the columns…in this example length of each column is the same but can be the different.

    I have attached workbook with few rows example, but in real max rows can be 65000

    Please help.

    Regards,
    Moti
    Attached Files Attached Files

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,675

    Re: Shuffle data only of the 3 columns

    May I ask:

    - These columns are independent of each other, so when shuffling, it only shuffles within that column, right?

    - After shuffling, the content of the items remains unchanged, only the positions within the column are altered, correct?

    It would be best if you could provide an example for one column, with 2 pieces of data: before and after the code runs.
    Quang PT

  3. #3
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by bebo021999 View Post
    May I ask:
    - These columns are independent of each other, so when shuffling, it only shuffles within that column, right?
    Hello bebo021999, thank you for asking a question here is my answer. Yes It is correct.

    Quote Originally Posted by bebo021999 View Post
    - After shuffling, the content of the items remains unchanged, only the positions within the column are altered, correct?
    This question gives me another idea instead of shuffling in the same columns can it be shuffled in the next Column I, J, K, L (original remain original) as per example sheet attached.

    Quote Originally Posted by bebo021999 View Post
    It would be best if you could provide an example for one column, with 2 pieces of data: before and after the code runs.
    Example sheet attached.

    Regards,
    Moti
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Shuffle data only of the 3 columns

    Run this in your first file

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by Motilulla View Post
    This question gives me another idea instead of shuffling in the same columns can it be shuffled in the next Column I, J, K, L (original remain original) as per example sheet attached.
    Ok I think it will be good shuffle in the same columns. (column D, column E, Column F).

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,173

    Re: Shuffle data only of the 3 columns

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  7. #7
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by JEC. View Post
    Run this in your first file
    JEC, thank you, Ok it is good shuffling in the same columns. (Column D, column E, Column F) no problem but there is one issue need 3 columns H, I, j empty and I got data in it.

    Regards,
    Moti

  8. #8
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,505

    Re: Shuffle data only of the 3 columns

    You could change that offset(,4) to offset(,99) everywhere

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Shuffle data only of the 3 columns

    Are you still using Excel 2010? If you have upgraded to 365, it would be very easy to shuffle into new columns.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,792

    Re: Shuffle data only of the 3 columns

    Says 2010 at the very top of post #1.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by TMS View Post
    Are you still using Excel 2010? If you have upgraded to 365, it would be very easy to shuffle into new columns.
    Hello TMS, yes using excel 2010, I need a VBA that shuffle in the same columns or in others but without the helper columns.

    Regards,
    Moti

  12. #12
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,675

    Re: Shuffle data only of the 3 columns

    OK, try below code:

    PHP Code: 
    Option Explicit
    Sub shuffle
    ()
    Dim lr&, i&, j&, r&, rngres(), tmp
    lr 
    Cells(Rows.Count"C").End(xlUp).Row
    rng 
    Range("C6:F" lr).Value
    For 2 To 4
        
    For 1 To UBound(rng) - 1
            r 
    WorksheetFunction.RandBetween(1UBound(rng))
            
    tmp rng(ij): rng(ij) = rng(rj): rng(rj) = tmp
        Next
    Next
    Range
    ("I6:L" lr).Value rng
    End Sub 
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Hello JohnTopley, Thank you, yes it seems to work fine without the helper columns. When I run the code it is erasing the original data in column F10 to down. Please can you check it?

    Regards,
    Moti

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    31,173

    Re: Shuffle data only of the 3 columns

    Please Login or Register  to view this content.
    Typo!

  15. #15
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by bebo021999 View Post
    OK, try below code:
    bebo021999, thank you, yes this worked perfect. Happy weekend.

    Regards,
    Moti

  16. #16
    Forum Contributor
    Join Date
    08-06-2006
    Location
    Spain
    MS-Off Ver
    Excel 2010 32Bit
    Posts
    545

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by JohnTopley View Post
    [CODE]Typo!
    JohnTopley, thank you, yes this worked spot on.

    Have a cheerful weekend.

    Regards,
    Moti

  17. #17
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Shuffle data only of the 3 columns

    Glad you have a solution.


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Shuffle data only of the 3 columns

    Quote Originally Posted by AliGW View Post
    Says 2010 at the very top of post #1.
    Missed that ... shoulda gone to SpecSavers

  19. #19
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: Shuffle data only of the 3 columns

    @Motilulla: Thanks for the rep, although the other guys did all the heavy lifting And I should have been paying more attention anyway

    Glad you have a solution

+ 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. How to shuffle all data in table
    By mr ray in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-10-2016, 07:56 AM
  2. How to shuffle all data in table
    By mr ray in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-09-2016, 11:01 PM
  3. Code to shuffle and paste columns from one sheet to another
    By saravanan1981 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2016, 02:19 PM
  4. [SOLVED] shuffle grid of data
    By Traymond in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-23-2016, 04:26 AM
  5. Sort/Shuffle Certain columns for a given row
    By Athenia413 in forum Excel General
    Replies: 5
    Last Post: 03-02-2014, 06:35 PM
  6. Randomly shuffle columns
    By Savan87 in forum Excel General
    Replies: 9
    Last Post: 06-10-2011, 10:50 AM
  7. shuffle 2 sets of data into 1
    By MrToast in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2011, 05:26 PM

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