Hi snb,
I have replaced my codes with the one you suggested for simple random sampling. And now I understand how simple and short is the code you suggested.
For the stratified sampling - Could you please guide me, how to apply rand() and rank based on each unique values in the filed selected both for equal and proportionate methods?Public LR As Long 'Last Row Public LC As Long ' Last Column Public SS As Long 'Sample Size SS = Me.txtRandomCount.Text With ActiveSheet .Cells(1, LC + 1) = "Sample" .Range(Cells(2, LC + 1), Cells(LR, LC + 1)).Name = "Sample" [Sample] = "=rand()" [Sample] = [index(rank(Sample,Sample),)] Set myrange = [Sample] For Each mycell In myrange If mycell.Value <= SS Then mycell.Value = "Yes" Else mycell.Value = Empty End If Next mycell End With




Reply With Quote