Random VBA with single criteria

grauer

New Member
Joined
Jun 21, 2016
Messages
3
Hi All

I have another issue. I have created a VBA code to randomly select 10 rows in a population of 46000 rows. The could looks as follows

Dim lRowNum(9) As Long, lCnt As Long, lrow As Long, i As Long
Do While lCnt < 10
lrow = Int(Selection.CurrentRegion.Rows.Count * Rnd + 1)
If Not IsNumeric(Application.Match(lrow, lRowNum, 0)) Then
lRowNum(lCnt) = lrow
lCnt = lCnt + 1
End If
Loop
Rows(1).Copy Sheets("Transaktions random kunder").Range("A1")
For i = LBound(lRowNum) To UBound(lRowNum)
Rows(lRowNum(i)).EntireRow.Copy Sheets("Transaktions random kunder").Range("A" & Sheets("Transaktions random kunder").Range("A" & Rows.Count).End(xlUp).Row + 1)
Next i

I have that issue, that i would like the 10 random rows to be based on a criteria in column AF. The column AF contains to different outcomes. Higher or Normal. Then i would like the rows to be 5 random rows with normal in AF column and the rest Higher in AF column.

Could Anyone help????

Thanks!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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