Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a sheet with approx 7,000 rows of data. Column A
has the value 1, 2 or 3 sorted into ascending order. I want to enter "R" in column D for 10% of the records with 2 or 3 in column A. If possible I would like this selection to be random (i.e. not just pick one in ten) so that if I were to run the macro twice I wouldn't get the same results. Thanks in advance. Gareth |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub EFG()
Dim lSize as Long, rng as Range Dim rng1 as Range, rng2 as Range Columns(4).ClearContents Range("A1:B1").EntireColumn.Insert Set rng = Range(Cells(1, 3), Cells(Rows.Count, 3).End(xlUp)) Set rng1 = rng.Find(2, After:=Range("C1")) Set rng2 = Range(rng1, rng(rng.Count)) rng2.Offset(0, -2).Resize(2, 1).Value = _ Application.Transpose(Array(1, 2)) rng2.Offset(0, -2).Resize(2, 1).AutoFill rng2.Offset(0, -2) rng2.Offset(0, -1).Formula = "=rand()" rng2.EntireRow.Sort Key1:=rng1.Offset(0, -1) lSize = Int(rng2.Count * 0.1) rng2.Offset(0, 3).Resize(lSize, 1).Value = "R" rng2.EntireRow.Sort Key1:=rng1.Offset(0, -2) Columns(1).Resize(, 2).Delete End Sub -- Regards, Tom Ogilvy "Gareth" wrote in message ... I have a sheet with approx 7,000 rows of data. Column A has the value 1, 2 or 3 sorted into ascending order. I want to enter "R" in column D for 10% of the records with 2 or 3 in column A. If possible I would like this selection to be random (i.e. not just pick one in ten) so that if I were to run the macro twice I wouldn't get the same results. Thanks in advance. Gareth |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I sum up random cells | Excel Worksheet Functions | |||
How to select other random cells | Excel Worksheet Functions | |||
#Value in random cells | Excel Worksheet Functions | |||
how to identify unique list of 200 random entries from a list of 3 | Excel Worksheet Functions | |||
Random select entries | Excel Discussion (Misc queries) |