Sitemap

Create your own train schedule dataset using Excel VBA

2 min readSep 25, 2025
Press enter or click to view image in full size

I have been studying statistics lately and have needed a few datasets for the projects that I have been working on. Because it is difficult to find datasets in Excel, I decided to use Excel VBA to create a simple dataset to use to schedule the number of trains needed on any day.

The screenshot below is the dataset that I have created. It contains five columns for:-

  • Date
  • Hour
  • Passenger count
  • Train capacity
  • Number of trains needed

Below is the code in Excel VBA to create the dataset in Excel.

The psuedocode for the code in VBA is:-

  1. Define all of the variables that will be needed to execute the program.
  2. Initialise start_date, end_date, and train capacity.
  3. Label the row 1 of the worksheet with the column headings.
  4. Initialise row_num as 2.
  5. Define a for loop for the start date that will increment to the stop date.
  6. Within the first for loop, define another for loop that will increment each hour of the day from 0 to 23.
  7. Each row within the second for loop will contain the day, hour, passenger count, train capacity, and number of trains needed.
  8. When the two for loops have iterated through 24 hours in a day and each day requested, a message will pop up saying the program has ended.
Press enter or click to view image in full size

The above program is a simple program that I put together in a few hours, and it contains the basic information needed to create a simple train schedule. This code can be modified to include more prompts to add more information to the dataset, such as including more trains that have a different capacity.

If you use the program and like it, please let me know.

I have created a code review to accompany this blog post, and it can be viewed here:- https://youtu.be/gh-pZ5RPMq4

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet