close

I need the following working UDF modified 2 ways

Function ROll2D6()
ROll2D6 = Application.RoundUp(Rnd() * 6, 0) Application.RoundUp(Rnd()
* 6, 0)
End Function

Way 1:
accept 2 integer inputs
int1 will tell the number of instances of Application.RoundUp(Rnd() * 6, 0)
to sum
int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
an exit check for if my.cell ISNUMBER()=TRUE

Way 2:
accept 2 integer inputs
int1 will tell the number of instances of Application.RoundUp(Rnd() * 6, 0)
to sum
int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
an exit check if the cell to the right =quot;failquot;

thanks
Adam Kroger lt;adam_kroger wrote:
gt; I need the following working UDF modified 2 ways
gt;
gt; Function ROll2D6()
gt; ROll2D6 = Application.RoundUp(Rnd() * 6, 0) Application.RoundUp(Rnd()
gt; * 6, 0)
gt; End Function
gt;
gt; Way 1:
gt; accept 2 integer inputs
gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6, 0)
gt; to sum
gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt; an exit check for if my.cell ISNUMBER()=TRUE
gt;
gt; Way 2:
gt; accept 2 integer inputs
gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6, 0)
gt; to sum
gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt; an exit check if the cell to the right =quot;failquot;
gt;
gt; thanks
gt;
gt;

Function ROll2D6(times As Long, mult As Long)
Dim i As Long
For i = 1 To times
ROll2D6 = ROll2D6 _
Application.RoundUp(Rnd() * mult, 0)
Next i
End FunctionDon't understandgt; an exit check for if my.cell ISNUMBER()=TRUEWhant I mean by an quot;exit checkquot; is that if the condition is true, then the
function would do nothing. for example

cell A1 has the formula =IF (B1=quot;Yquot;,RollDice(2,6),quot;quot;)

Function RollDice(times As Long, mult As Long)
Dim i As Long
For i = 1 To times
ROll2D6 = ROll2D6 _
Application.RoundUp(Rnd() * mult, 0)
Next i
End Function

what I want is some type of check whereby if tRollDice has already run once
in Cell A1 and generated a number, then it will not do it again the next
time the WorkBook refreashes the data. Using quot;pidgen languagequot; programming
I would envision it looking something like this:

Function RollDice(times As Long, mult As Long)
Dim i As Long
IF ISNUMBER(my.cell)
GoTo End Function
For i = 1 To times
ROll2D6 = ROll2D6 _
Application.RoundUp(Rnd() * mult, 0)
Next i
End Function

with my.cell referring to the cell that called the function.

I would also like know how to specify an OFFSET() from my.cell to perform
the same sort of quot;exit checkquot;
Function Whatever()
IF OFFSET(my.cell, 1,-1)=quot;failquot;
GoTo End
lt;function codegt;
End Function

Does that make more sense? I guess my questions fall more into the quot;How do
you do this?quot; catagory.

I wish there was a quot;Programming UDFs for Dummiesquot; on the web somewhere, that
would walk you through the basics of creating, and implementing a UDF. The
documentation that I have managed to find doesn't really explain the quot;Howquot;
or quot;Whyquot; just gives you some code that people have found useful. I do have
some basic (type not language, though I played around in that also, back
when dinosaurs roamed the earth) programming knowledge. I just don't really
know where to start, nor what the excel specific constants, and commands are
(how to declare variables, get user input, evaluate data, negotiate around
excel, etc).
quot;Bob Phillipsquot; gt; wrote in message
...
gt; Adam Kroger lt;adam_kroger wrote:
gt;gt; I need the following working UDF modified 2 ways
gt;gt;
gt;gt; Function ROll2D6()
gt;gt; ROll2D6 = Application.RoundUp(Rnd() * 6, 0)
gt;gt; Application.RoundUp(Rnd()
gt;gt; * 6, 0)
gt;gt; End Function
gt;gt;
gt;gt; Way 1:
gt;gt; accept 2 integer inputs
gt;gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6,
gt;gt; 0)
gt;gt; to sum
gt;gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt;gt; an exit check for if my.cell ISNUMBER()=TRUE
gt;gt;
gt;gt; Way 2:
gt;gt; accept 2 integer inputs
gt;gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6,
gt;gt; 0)
gt;gt; to sum
gt;gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt;gt; an exit check if the cell to the right =quot;failquot;
gt;gt;
gt;gt; thanks
gt;gt;
gt;gt;
gt;
gt; Function ROll2D6(times As Long, mult As Long)
gt; Dim i As Long
gt; For i = 1 To times
gt; ROll2D6 = ROll2D6 _
gt; Application.RoundUp(Rnd() * mult, 0)
gt; Next i
gt; End Function
gt;
gt;
gt; Don't understand
gt;
gt;
gt; gt; an exit check for if my.cell ISNUMBER()=TRUE
gt;
usnig the function is a cell in this manner :
=IF(W12=TRUE,RollDice(2,6),quot;quot;)

The function returns 0 every time.

When I modified it by frankensteining what you wronte into another sample
function I came up wiht this function:

Function RollDice(times As Long, mult As Long)
Dim i As Long
Dim myTemp As Integer
Randomize
myTemp = 0
For i = 1 To times
myTemp = myTemp Application.RoundUp(Rnd() * mult, 0)
Next i
myCell.Value = myTemp
End Function

but it returns #VALUE!

any suggestions?

quot;Adam Kroger @hotmail.comgt;quot; lt;adam_krogerlt;nospamgt; wrote in message
...
gt; Whant I mean by an quot;exit checkquot; is that if the condition is true, then the
gt; function would do nothing. for example
gt;
gt; cell A1 has the formula =IF (B1=quot;Yquot;,RollDice(2,6),quot;quot;)
gt;
gt; Function RollDice(times As Long, mult As Long)
gt; Dim i As Long
gt; For i = 1 To times
gt; ROll2D6 = ROll2D6 _
gt; Application.RoundUp(Rnd() * mult, 0)
gt; Next i
gt; End Function
gt;
gt; what I want is some type of check whereby if tRollDice has already run
gt; once in Cell A1 and generated a number, then it will not do it again the
gt; next time the WorkBook refreashes the data. Using quot;pidgen languagequot;
gt; programming I would envision it looking something like this:
gt;
gt; Function RollDice(times As Long, mult As Long)
gt; Dim i As Long
gt; IF ISNUMBER(my.cell)
gt; GoTo End Function
gt; For i = 1 To times
gt; ROll2D6 = ROll2D6 _
gt; Application.RoundUp(Rnd() * mult, 0)
gt; Next i
gt; End Function
gt;
gt; with my.cell referring to the cell that called the function.
gt;
gt; I would also like know how to specify an OFFSET() from my.cell to perform
gt; the same sort of quot;exit checkquot;
gt; Function Whatever()
gt; IF OFFSET(my.cell, 1,-1)=quot;failquot;
gt; GoTo End
gt; lt;function codegt;
gt; End Function
gt;
gt; Does that make more sense? I guess my questions fall more into the quot;How
gt; do you do this?quot; catagory.
gt;
gt; I wish there was a quot;Programming UDFs for Dummiesquot; on the web somewhere,
gt; that would walk you through the basics of creating, and implementing a
gt; UDF. The documentation that I have managed to find doesn't really explain
gt; the quot;Howquot; or quot;Whyquot; just gives you some code that people have found useful.
gt; I do have some basic (type not language, though I played around in that
gt; also, back when dinosaurs roamed the earth) programming knowledge. I just
gt; don't really know where to start, nor what the excel specific constants,
gt; and commands are (how to declare variables, get user input, evaluate data,
gt; negotiate around excel, etc).
gt;
gt;
gt;
gt; quot;Bob Phillipsquot; gt; wrote in message
gt; ...
gt;gt; Adam Kroger lt;adam_kroger wrote:
gt;gt;gt; I need the following working UDF modified 2 ways
gt;gt;gt;
gt;gt;gt; Function ROll2D6()
gt;gt;gt; ROll2D6 = Application.RoundUp(Rnd() * 6, 0)
gt;gt;gt; Application.RoundUp(Rnd()
gt;gt;gt; * 6, 0)
gt;gt;gt; End Function
gt;gt;gt;
gt;gt;gt; Way 1:
gt;gt;gt; accept 2 integer inputs
gt;gt;gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6,
gt;gt;gt; 0)
gt;gt;gt; to sum
gt;gt;gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt;gt;gt; an exit check for if my.cell ISNUMBER()=TRUE
gt;gt;gt;
gt;gt;gt; Way 2:
gt;gt;gt; accept 2 integer inputs
gt;gt;gt; int1 will tell the number of instances of Application.RoundUp(Rnd() * 6,
gt;gt;gt; 0)
gt;gt;gt; to sum
gt;gt;gt; int2 will replace the 6 in Application.RoundUp(Rnd() * 6, 0)
gt;gt;gt; an exit check if the cell to the right =quot;failquot;
gt;gt;gt;
gt;gt;gt; thanks
gt;gt;gt;
gt;gt;gt;
gt;gt;
gt;gt; Function ROll2D6(times As Long, mult As Long)
gt;gt; Dim i As Long
gt;gt; For i = 1 To times
gt;gt; ROll2D6 = ROll2D6 _
gt;gt; Application.RoundUp(Rnd() * mult, 0)
gt;gt; Next i
gt;gt; End Function
gt;gt;
gt;gt;
gt;gt; Don't understand
gt;gt;
gt;gt;
gt;gt; gt; an exit check for if my.cell ISNUMBER()=TRUE
gt;gt;
gt;
gt;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()