Copying 2/3 unique values from range of data but ramdomly - Is this a possible function in Excel VBA?

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
I am wanting to copy 2/3 unique values from range of data from B col till last row but ramdomly - Is this a possible function in Excel VBA? The data will contain > 1000 rows of datas.:)

Thanks for helping in advance.
 
I found two related errors. Once fixed, it works fine. (Although you may want to adjust the number of columns in the definition of dataRange.)

1) The function selectFrom is missing. Copy the code below into the module.
2) The line that errors should be
Code:
choiceArray = selectFrom(Array1to(batchCount), selectionCount)

I may have caused the confusion. The upgraded function Array1To that I posted in #12 (and you used) was supposed to replace the function Array1To in #11.
I should have made it clear that selectFrom was still needed.

Here's the function selectFrom that should be added to the module.
Code:
Function selectFrom(ByVal anArray As Variant, Optional selectCount As Long) As Variant
    Dim i As Long, Size As Long, randIndex As Long, temp As Variant
    Size = UBound(anArray)
    If selectCount < 1 Then selectCount = Size
    
    For i = 1 To selectCount
        randIndex = 1 + Int(Rnd() * Size)
        temp = anArray(i)
        anArray(i) = anArray(randIndex)
        anArray(randIndex) = temp
    Next i
    ReDim Preserve anArray(1 To selectCount)
    selectFrom = anArray
End Function
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Mike, thank you soo much for helping me out. Sometime it still erros in the same line with same error.
let me get back if it still cont. to error.


Thanks again. ' appriciate your help. :)
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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