Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I sum up random cells Josh W Excel Worksheet Functions 25 April 2nd 23 07:56 PM
How to select other random cells Chad Excel Worksheet Functions 0 April 23rd 10 02:49 PM
#Value in random cells Michael Excel Worksheet Functions 2 June 19th 09 06:31 PM
how to identify unique list of 200 random entries from a list of 3 tjb Excel Worksheet Functions 3 August 13th 07 02:15 PM
Random select entries brodiemac Excel Discussion (Misc queries) 2 September 9th 06 03:01 AM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"