newagepc.com.au

  • Increase font size
  • Default font size
  • Decrease font size
Home Code Examples Microsoft Office Excel VBA Code
Microsoft Office Excel VBA Code

Programatic Times Tables in Excel VBA

E-mail Print PDF

I was thinking of typing up a list of times tables for my boys to learn from when i thought to myself, how hard could it be to automate it using excels VBA scripting engine. Well turns out it's super easy and thought i would share the source code for anyone that may be more lazy than me :)

For the standard times tables when prompted enter 12 enter than 12 again.


Sub times_tables()

'get information for how many columns and rows we want
ihor = InputBox("how many tables?")
iver = InputBox("how many times?")

'horizintal iteration
For e = 1 To ihor

'verticle iteration
For i = 1 To iver
'output to cell
ActiveCell.Cells(i, e) = i & " * " & e & " = " & i * e

Next
Next
End Sub


A quick walk through of the VBA code would go something like;

a) get two inputs from the user for both the number of columns and number of rows.

b) run two loops iterating vertically then horizontally.

c) output where the cursor is per loop integers the times tables.

Happy scripting,

Last Updated on Saturday, 12 June 2010 12:42
 


Newsflash

Hmmm... Make sure you have adobe flash player installed, http://www.adobe.com and enable java.
eXTReMe Tracker