Create your own train schedule dataset using Excel VBA
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:-
- Define all of the variables that will be needed to execute the program.
- Initialise start_date, end_date, and train capacity.
- Label the row 1 of the worksheet with the column headings.
- Initialise row_num as 2.
- Define a for loop for the start date that will increment to the stop date.
- Within the first for loop, define another for loop that will increment each hour of the day from 0 to 23.
- Each row within the second for loop will contain the day, hour, passenger count, train capacity, and number of trains needed.
- 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.
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
