How to Generate Random Addition and Subtraction Worksheets in Word
Question details
The user wants to generate random single-digit addition and subtraction equations in a formatted Word worksheet without having to type and format each document manually.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A teacher is preparing customized math practice worksheets for students and needs a quick, automated way to create multiple unique worksheets.
- Observed behavior
- Instead of manual entry, the user seeks an automated VBA solution that instantly populates a document with random math problems in a standardized format.
Ensure that the Developer tab is enabled in your Word processor's ribbon so you can access the VBA Editor, and make sure macro security settings allow you to run custom scripts.
Use a VBA Macro to Populate a Table with Random Equations
By setting up a simple table and using a VBA macro, you can instantly fill the document with randomized math equations, avoiding manual typing.
This method uses a macro to iterate through a table in your document. It automatically assigns random numbers between 1 and 9 to the first and third columns, a random addition or subtraction operator to the second column, and an equals sign to the fourth column. The fifth column acts as the blank space for the student to write the answer.
Open a new blank document. Go to the Insert tab, select Table, and insert a table with 5 columns and as many rows as the number of equations you need (e.g., 5 columns by 20 rows). Format the 5th column by applying a bottom border to create an 'answer line' for the students.
Press 'Alt + F11' on your keyboard to open the Visual Basic for Applications (VBA) Editor. In the top menu, click 'Insert' > 'Module' to create a new blank script window.
Copy and paste the following code into the Module window: Sub FillTable() Dim tbl As Table Dim rw As Row Set tbl = ActiveDocument.Tables(1) Randomize For Each rw In tbl.Rows rw.Cells(1).Range.Text = Int(9 * Rnd + 1) rw.Cells(2).Range.Text = IIf(Rnd > 0.5, "+", "-") rw.Cells(3).Range.Text = Int(9 * Rnd + 1) rw.Cells(4).Range.Text = "=" Next rw End Sub
Close the VBA editor and return to your document. Press 'Alt + F8', select 'FillTable' from the list, and click 'Run'. The table will instantly fill with randomized equations. You can run this macro again anytime to generate a completely new set of problems.

Automate Your Worksheets Easily with WPS Writer
WPS Writer offers seamless table formatting and developer tools (in its Pro version) to easily execute VBA macros, empowering teachers and educators to quickly generate customized math worksheets for their classrooms.
- 1. Create a New Document: Open WPS Writer and start a new blank document from the homepage.
- 2. Insert a 5-Column Table: Navigate to the Insert tab, click on Table, and draw a 5-column grid for your math problems.
- 3. Open Developer Tools: Go to the Developer tab and click on the VBA Editor icon to input your worksheet generation script.
- 4. Run and Export: Execute the macro to populate the table, then easily export the worksheet as a PDF for printing.

Frequently Asked Questions
Can I modify the macro to generate double-digit math problems?
Yes. To generate double-digit numbers, you can change the formula in the VBA code from 'Int(9 * Rnd + 1)' to 'Int(90 * Rnd + 10)'. This will output random numbers between 10 and 99.
Why do my numbers stay the same every time I open the document?
If the numbers do not change, ensure that the 'Randomize' command is included in your VBA script right before the loop starts. The 'Randomize' statement resets the random number seed, ensuring a unique sequence each time the macro runs.
How can I include multiplication and division in the worksheet?
You can expand the 'IIf' function in the second cell's code to randomly select between '+', '-', '*', and '/'. For example, you can use a 'Select Case' statement tied to a random number between 1 and 4 to pick the corresponding math operator.




