View Single Post
 
Old 09-18-2014, 11:00 PM
excelledsoftware excelledsoftware is offline Windows 7 64bit Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default RandBetween for PowerPoint

I am making a powerpoint that presents the user with a problem from an array list. I want to be able to pull a random problem from the array and I like the RandBetween Function in Excel. I know there are otherways to do this but the RandBetween is so simple. How can I make the following work?
Code:
Sub PullRandom()

  Dim TestArray as Variant, RandNum as integer, xls as object

  TestArray = Array("1+1","2+2","3+3")
  set xls = createobject("Excel.application")
  RandNum = xls.worksheetfunction.RandBetween(lbound(TestArray), ubound(TestArray))
  
  debug.print RandNum
End Sub
Any idea on how to get this work would be very helpful. I know that I can already use the following to accomplish this but I would like to figure out the RandBetween

Code that works
Code:
    TotalProblems = UBound(TestArray) + 1
    z = Int(Rnd() * TotalProblems) + 1
    Debug.Print TestArray(z - 1)
Thanks in advance
Reply With Quote