Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Random Select

Hi, Ive got 3 sheets of data, doesnt completly fill each sheet but
almost. Id like to randomly select a block of cells in a columm. eg
a1:a100, a100:a200 etc. across the 3 sheets. Im guessing id randomly
select the sheet then select the cells. Then Id like to loop through
the selected cells. Any ideas please.
Regards Robert

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Random Select

Sub pick_a_bunch()
'
'pick a randon sheet
'
n = Evaluate("Randbetween(1,3)")
Sheets(n).Activate
'
'pick a random column
'

cols = "randbetween(1," & Columns.Count & ")"
col = Evaluate(s)
'
'pick random row range
'
s = "randbetween(1," & Rows.Count & ")"
rStart = Evaluate(s)
s2 = "randbetween(" & rStart & "," & Rows.Count & ")"
rEnd = Evaluate(s2)

For i = rStart To rEnd
MsgBox (Cells(i, cols).Address)
Next

End Sub


--
Gary''s Student - gsnu2007


"RobcPettit" wrote:

Hi, Ive got 3 sheets of data, doesnt completly fill each sheet but
almost. Id like to randomly select a block of cells in a columm. eg
a1:a100, a100:a200 etc. across the 3 sheets. Im guessing id randomly
select the sheet then select the cells. Then Id like to loop through
the selected cells. Any ideas please.
Regards Robert


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Random Select

Try this

Sub rancells()

Const MaxRow = 1000
Dim RandRange(3)

For shtcount = 1 To 3
Num1 = (MaxRow * Rnd()) + 1
Num2 = (MaxRow * Rnd()) + 1
If mum1 < Num2 Then
FirstRow = Int(Num1)
LastRow = Int(Num2)
Else
FirstRow = Int(Num2)
LastRow = Int(Num1)
End If
With Sheets(shtcount)
Set RandRange(shtcount - 1) = _
.Range("A" & FirstRow & ":A" & _
LastRow)
End With
Next shtcount

For shtcount = 1 To 3
For Each cell In RandRange(shtcount - 1)
'enter your code here
Next cell
Next shtcount
End Sub

"RobcPettit" wrote:

Hi, Ive got 3 sheets of data, doesnt completly fill each sheet but
almost. Id like to randomly select a block of cells in a columm. eg
a1:a100, a100:a200 etc. across the 3 sheets. Im guessing id randomly
select the sheet then select the cells. Then Id like to loop through
the selected cells. Any ideas please.
Regards Robert


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Random Select

Thankyou both for your help. Done the trick. Sorry for delay in reply
been away. Much appreciated.
Regards Robert

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
Select a random sample IPMS Excel Discussion (Misc queries) 2 January 7th 07 02:54 AM
Random Select one of two or more numbers mark_varney47[_7_] Excel Programming 2 August 18th 06 04:27 AM
How can I select random whole nos from 1-16 without repeating? ilena Excel Programming 3 December 14th 05 07:35 AM
Select random cell SammyJJones Excel Worksheet Functions 4 November 11th 05 01:56 AM
Select a random cell < 1 Jason Morin[_3_] Excel Programming 3 April 17th 04 04:24 PM


All times are GMT +1. The time now is 10:04 AM.

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

About Us

"It's about Microsoft Excel"