![]() |
entries into random cells
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 |
entries into random cells
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 |
All times are GMT +1. The time now is 06:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com