View Single Post
 
Old 03-21-2017, 10:19 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

This looks fun, but it will take some thought how to record who has which version, but something along the lines of the following may help get you started.

Code:
Option Explicit
Private Const sName As String = "Billy|Bobby|John|Susan|Ted"
Private Const sPlace As String = "Cliff|Tower|Bridge"
Private Const sItem As String = "Stone|Rock|Wrench"
Private vName As Variant, vPlace As Variant, vItem As Variant
Private iPlace As Integer, iName As Integer, iItem As Integer
Private iHeight As Integer, iMass As Integer
Private sText As String

Private Function RandomNumber(Lowest As Long, Highest As Long, _
                              Optional Decimals As Integer) As Integer
    If IsMissing(Decimals) Or Decimals = 0 Then
        Randomize
        RandomNumber = Int((Highest + 1 - Lowest) * Rnd + Lowest)
    Else
        Randomize
        RandomNumber = Round((Highest - Lowest) * Rnd + Lowest, Decimals)
    End If
End Function

Sub Macro1()
    vName = Split(sName, "|")
    vPlace = Split(sPlace, "|")
    vItem = Split(sItem, "|")
    iHeight = RandomNumber(1, 50, 0)
    iMass = RandomNumber(1, 5, 0)
    iPlace = RandomNumber(0, UBound(vPlace))
    iName = RandomNumber(0, UBound(vName))
    iItem = RandomNumber(0, UBound(vItem))
    sText = vName(iName) & " dropped a " & vItem(iItem) & " off a " & iHeight & " meter-high " & _
            vPlace(iPlace) & ". The " & vItem(iItem) & " has a mass of " & iMass & " kilograms."
    Selection.TypeText sText
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote