Hello everyone,
I'm *extremely* new to VBA programming (just started about an hour ago), though i'm well versed in other languages.
I play a game called Dungeons and Dragons with some friends, and I was looking into an integrated solution for rolling a bunch of dice (-- i.e. 36d6 (36 - 6 sided dice)) onto our character sheets, which are in excel.
I figured that the most elegant solution would be to have a macro that would read a string, and then take from it what it needs to make the appropriate calculation.
WHAT I WOULD LIKE THE PROGRAM TO DO:
read a string from a cell, and parse the necessary information, being stored into the appropriate variables (num - loop control, size - max of Randbetween)
use a FOR loop to generate a number between 1 and max
add generated number to 'answer' variable
iterate until completion
return answer to given cell
'=======EXAMPLE======='
string to read: 2d6
num = 2
max = 6
answer = 0
tmp = 0
'loop num times to generate numbers between 1 and max'
first iteration: tmp = 3
answer = answer + tmp
second iteration: tmp = 5
answer = answer + tmp
'loop exits'
return answer 'to given cell'
'=======END EXAMPLE======='
I apologize up front if I overcomplicated either my attempt at a solution, or the phrasing of my inquiry.
My code:
The error I receive when attempting to run my code:Please Login or Register to view this content.
VBA error.png
Bookmarks