Excel Help (in Off-topic)

AdminQBGentlemanLoser [{END}] December 15 2011 5:19 AM EST

At work, I've been tinkering aorund with Excel, trying to expand my knowledge of it by trying to make the basics of a little PvP type fight game. ;)

Just the bare basics atm, I've got a field with a validated list of 1 to 10 for attack and defense (twice, once for the attacker and defender). Next to these are 10 columns that choose a random number from 1-10, a number of times from 1 to 10. If that makes sense!

So the first cell is a random number from 1-10. The next creates two random numbers both form 1-10, the third cell 3, and so on.

Below these, I choose the maximum result from each of the random numbers created. ;)

This forms an Attack and Defend score, which generates damage done.

I have bound a Macro to a button to recalculate the forumla each time it's clicked, to simulate another roll of the dice, so to speak.

But now I've come to a slight dead end.

The next thing I want to do is record damage done.

But I can't figure out a way to store the results done. If that makes sense as well!

Starting with 'Hit Points' of 100, I can reduce this amount by the damage done each click of the macro. But it will always reset back.

I can't figure out a way to store the result in Excel.

Does anyone have any ideas/suggestions?

Thanks! :D

{WW]Nayab [Cult of the Valaraukar] December 15 2011 7:45 AM EST

Sounds like something you would need to do manually.
When i used excel for random number generation, i would do a number of trials and record the results in a different part of the page.
I certainly don't know a way to make excel create a tally of the various numbers you generate. Sure as heck would like to know though :O

AdminQBGentlemanLoser [{END}] December 15 2011 8:03 AM EST

Something with Macros and Date Stamps maybe? :/

Admindudemus [jabberwocky] December 15 2011 8:19 AM EST

instead of a macro, is there anyway you could used nested if statements and the rand function?

AdminTitan December 15 2011 9:03 AM EST

Or instead of Excel you just use Python, it'd probably be way way way easier to do it with a real language, even if you don't know how to program.

AdminQBGentlemanLoser [{END}] December 15 2011 9:07 AM EST

I did a C++ course about 10 years ago. :/

If only I could find an old Football Management game I had in Excel years ago, I could break the protection on it and rifle through it's secrets. ;)

I can't think of any easy way to do this in Excel, which is disappointing. :(

AdminTitan December 15 2011 9:58 AM EST

If you want me to show you the basics of Python I could, it's nothing like C++; like literally magnitudes easier. You could do something like the above in 5-10 minutes. There are also a lot of tutorials online as well. Also Python is easy to install on all popular OSes.

AdminQBGentlemanLoser [{END}] December 15 2011 10:49 AM EST

Oh. Lovely! :D

Where would be the best place to start?

(I'm only slightly disappointed. I love Excel and this it's a very powerful too. I would have liked there to be a way to do this in Excel itself. ;) )

AdminTitan December 15 2011 10:57 AM EST


These tutorials look really good from the little bit I've watched, they're like 5 mins or so a piece. I'd recommend watching a few, and then just playing around with Python. If you've done any programming at all this should come really easy to you, b/c python syntax is like pseudo-code with no memory management. If you have any questions you can CM me or catch me in chat. Also, this is a good website to look stuff up about built in stuff in python:


Also, googling always works; there's a lot of info out there about python.

QBsutekh137 December 16 2011 10:13 AM EST

Not sure I understand... You want to store data in Excel? So store the data in cells at a known location. Excel is no database, but it can certainly store a lot of data. *smile*

The other thing to look at would be variable scope. I am thinking you can great global variables in Excel. That would mean they don't reset every time the macro runs (the scope of your current counter appears to be limited to the macro, so it resets every time, as it should...) Here's a quick thread I found about declaring global vars in Excel:


The "real" way to do this would be with a database. I could whip something out in Visual Foxpro in moments, but that wouldn't help you much. Python is a nice recommendation because it has a nifty command-line mode so you can tinker with things and learn as you go. Visual Studio (.NET) also has a free version and you can program in either C# or Visual Basic). In python, you can link to several db back-ends, from flat-file implementations all the way up to something like PostgreSQL (which is what CB runs on, I believe) would work.

If you need more help we can start emailing Excel sheets back and forth. I usually manipulate Excel via COM automation from VFP, but that has taught me quite a bit about what macro code looks like under the hood in Excel.

QBsutekh137 December 16 2011 10:14 AM EST

Ack, typo...

I am thinking you can great global...

should be

I am thinking you can create global...
This thread is closed to new posts. However, you are welcome to reference it from a new thread; link this with the html <a href="/bboard/q-and-a-fetch-msg.tcl?msg_id=003G4O">Excel Help</a>