Skip to content

Instantly share code, notes, and snippets.

@palikhov
Created February 8, 2022 08:50
Show Gist options
  • Save palikhov/c6be257795716613943668737f8fb9ad to your computer and use it in GitHub Desktop.
Save palikhov/c6be257795716613943668737f8fb9ad to your computer and use it in GitHub Desktop.
primitive macro to dice formula excel
Sub DiceXlator()
Dim r As Range, v As String, NewForm As String, deemode As Boolean
Dim dee As String
dee = "d"
deemode = False
For Each r In Selection
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
r.Offset(0, 1).Formula = NewForm
Next r
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment