PC Review


Reply
Thread Tools Rate Thread

VBA pick random cell - print

 
 
flashing frank
Guest
Posts: n/a
 
      23rd Nov 2004

hi,
i want to pick a random cell (containing text) in a given range.

i used the "randbetween" function in excel, but i am now needing thi
in visual basic.

i found the following vba snipplet, but i donīt understand it, an
canīt implement it in my code:


PHP code
-------------------
With Range("B1")
.FormulaR1C1 = _
"=OFFSET(Sheet1!RC[-1],RANDBETWEEN(0,9),0)"

-------------------
it would be great if someone could give me an example of picking
random cell in the range lets say ("A1:B10")

i would also like to know how to combine two random picks with th
print function.
something like:

Print #1, (function for random cell1 ("a1:B10")) & (function for rand
cell2 ("C3:C10"))

i hope i described my problem good enough...

thank

--
flashing fran
-----------------------------------------------------------------------
flashing frank's Profile: http://www.excelforum.com/member.php...fo&userid=1375
View this thread: http://www.excelforum.com/showthread.php?threadid=31984

 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      23rd Nov 2004
>>it would be great if someone could give me an example of picking a
random cell in the range lets say ("A1:B10")

Okay, here such a function:

Function RandCell(Rg As Range) As Range
Set RandCell = Rg.Cells(Int(Rnd * Rg.Cells.Count) + 1)
End Function

and here's a test to satisfy yourself it's working. I'm sure you can hook
RandCell into your code.

Sub RandCellTest()
Dim Counter As Long
Dim TargetRg As Range
Application.ScreenUpdating = False
Set TargetRg = Range("A1:A10")
TargetRg.ClearContents
Dim Cell As Range
For Counter = 1 To 10000
Set Cell = RandCell(TargetRg)
Cell.Value = Cell.Value + 1
Next
End Sub

--
Jim Rech
Excel MVP


 
Reply With Quote
 
 
 
 
flashing frank
Guest
Posts: n/a
 
      24th Nov 2004

thanks works fine :

--
flashing fran
-----------------------------------------------------------------------
flashing frank's Profile: http://www.excelforum.com/member.php...fo&userid=1375
View this thread: http://www.excelforum.com/showthread.php?threadid=31984

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pick random cell in VBA Flammy Microsoft Excel Misc 0 20th Apr 2011 01:50 AM
Re: HELP!!! ***res://<random>.dll/<random>.html#<random>*** HELP!!! The Stull Demon Windows XP Security 0 1st Jul 2004 03:55 AM
Re: HELP!!! ***res://<random>.dll/<random>.html#<random>*** HELP!!! The Stull Demon Windows XP Security 13 30th Jun 2004 03:02 PM
HELP!!! ***res://<random>.dll/<random>.html#<random>*** HELP!!! The Stull Demon Windows XP Internet Explorer 1 29th Jun 2004 01:11 AM
HELP!!! ***res://<random>.dll/<random>.html#<random>*** HELP!!! The Stull Demon Windows XP Security 2 28th Jun 2004 10:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:28 AM.