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

I need to write a macro for Excel that will keep on generating a rando
number until a condition is met. The values compared are on th
spreadsheet and I dont know how to call them in VB.
Any help is greatly at all is welcome

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default loop random number


Sub AABB()
Range("B1") = Int(Rnd() * 1000 + 1)
If IsNumeric(Range("C1")) Then
If Range("C1") < 1000 And Range("C1") 1 Then
Do While Range("B1") Range("C1")
Range("B1") = Int(Rnd() * 1000 + 1)
Loop
End If
End If
End Sub


as an example.

--
Regards,
Tom Ogilvy





"mrmark " wrote in message
...
I need to write a macro for Excel that will keep on generating a random
number until a condition is met. The values compared are on the
spreadsheet and I dont know how to call them in VB.
Any help is greatly at all is welcome.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop random number

Well its like this there is this equation I have in a spreadsheet I hav
in one cell B15 the right side of the equation and in B16 I have th
left side of the equation and I want excel to keep generating value
until both sides are equal, would a random number actually be able t
help with this

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default loop random number

Ok I have written some of my own code and I dont know if it works or no
because I get the "That name is not valid" box when I call the macro.
but heres the code
Sub numberct()
'
' numberct Macro
' Macro recorded 6/22/2004 by y98
'

'
If Range("B15") < Range("B16") Then
Range("B17") = Int(Rnd() * 0.009)
ElseIf Range("B15") = Range("B16") Then
Range("B17") = ""
End If

End Su

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default loop random number

Code runs fine for me. If B17 is involved in the calculation of the
formulas, then it seems setting it to "" would change the values being
returned by B15 and B16.

If you are just using rnd to stimulate a calculation (and it (B17) isn't
referenced by the formula), you can just use ActiveSheet.CalculateFull in
Excel 2000 and later

If the calculations are returning floating point numbers, it is probable
that they will never return equal numbers.

--
Regards,
Tom Ogilvy

"mrmark " wrote in message
...
Ok I have written some of my own code and I dont know if it works or not
because I get the "That name is not valid" box when I call the macro.
but heres the code
Sub numberct()
'
' numberct Macro
' Macro recorded 6/22/2004 by y98
'

'
If Range("B15") < Range("B16") Then
Range("B17") = Int(Rnd() * 0.009)
ElseIf Range("B15") = Range("B16") Then
Range("B17") = ""
End If

End Sub


---
Message posted from http://www.ExcelForum.com/



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 can I match a random number with closest number from sequence? Matt Excel Worksheet Functions 4 August 3rd 06 01:22 AM
same number appears in a random number generator Carmel Excel Worksheet Functions 4 May 28th 06 12:22 AM
Generating (in a random order)each number once from a given number Neil Goldwasser Excel Worksheet Functions 2 December 2nd 05 11:27 PM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM
random number generation: loop NickC[_2_] Excel Programming 2 January 23rd 04 07:37 AM


All times are GMT +1. The time now is 05:53 PM.

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"