Created
February 8, 2022 08:48
-
-
Save palikhov/430fd7d91dbd5f5888210f61cb79147d to your computer and use it in GitHub Desktop.
UDF Roll Dice Formula
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Function RollDice(r As Range) As Variant | |
| Application.Volatile | |
| Dim v As String, NewForm As String, deemode As Boolean | |
| Dim dee As String | |
| dee = "d" | |
| deemode = False | |
| v = r.Value | |
| NewForm = "=" | |
| For i = 1 To Len(v) | |
| ch = Mid(v, i, 1) | |
| If ch = dee Then | |
| NewForm = NewForm & "*RANDBETWEEN(1," | |
| deemode = True | |
| Else | |
| If Not IsNumeric(ch) And deemode Then | |
| deemode = False | |
| NewForm = NewForm & ")" | |
| End If | |
| NewForm = NewForm & ch | |
| End If | |
| Next i | |
| If deemode Then | |
| NewForm = NewForm & ")" | |
| End If | |
| RollDice = Evaluate(NewForm) | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment