Randomly ruffling column datas by vba code

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Good Day,

Below code is shuffling column A1 name list randomly.
Is it possible to control the code from another worksheet?
I wanna place the button into different worksheet to hide main data.
What will be the add into that code?
Many Thanks


VBA Code:
Sub ruffle_Button1_Click()
Dim r As Long, c As Long, RandomIndex As Long, Data As Variant, Result As Variant
        For i = 1 To 500
        Randomize
        Data = Range("A1").CurrentRegion.Value
        ReDim Result(1 To UBound(Data, 1), 1 To UBound(Data, 2))
        For r = UBound(Data, 1) To 1 Step -1
            RandomIndex = Int(r * Rnd + 1)
            For c = 1 To UBound(Data, 2)
                Result(r, c) = Data(RandomIndex, c)
                Data(RandomIndex, c) = Data(r, c)
            Next
        Next
        Range("A1").CurrentRegion = Result
    Next
End Sub
 

Excel Facts

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

Code:
Data = Range("A1").CurrentRegion.Value
...
Range("A1").CurrentRegion = Result

to:

Code:
Data = Sheets("main data"). Range("A1").CurrentRegion.Value' Changge sheet name here.
...
Sheets("main data"). Range("A1").CurrentRegion = Result 'Changge sheet name here.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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