Could someone give some tips about running simulation on excel?

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
375
Office Version
  1. 365
Platform
  1. Windows
Gurus,
suppose that I have a dataset that provides the arrival time of trucks for days and another dataset that provides the truckload that everything truck brings.
how do I run a simulation and come up with a graph that shows the accumulated truckload of a typical day when 10000trucks com in? Thanks!
Untitled.png
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
The way I would do this is to look at the arrival times data and find out what the smallest interval is between two arrivals. This interval interval is the “tick” time.

So the sort the arrivals data into time order.

Then load it into a variant array to make the whole process much faster.

Load the truck load data into another variant

Initialise an output variant array with sufficient rows to account for all ticks

Set up some variable initialised to zero, for number of truck and the total load

You want to start you “simulated clock” just before the first time so create a loop from this start time to just after the last start time with the step being the “tick” time.

Write out the time and current values of the truck load and number of trucks to the output array every iteration

Then you can check this time against initially the first time of arrival in your data and if this time is before or equal to your simulated clock you add that load into total load and add one to the truck count, you then increment a count by one so that the next time you do this check you are checking the second truck to arrive etc,etc.
Just as an example here is some code:
VBA Code:
Sub test()
starttime = TimeValue("06:00:00")
endtime = TimeValue("18:00:00")
indi = 1
For i = starttime To endtime Step TimeValue("01:00:00")
 If i > Time() Then ' use the current truck time instead here
 Cells(indi, 1) = CStr(i)  ' use a variant array instead of writing directly to the cells
 indi = indi + 1      ' note you have to keep a separate count of where you are for input and output
 End If
Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,240
Messages
6,054,317
Members
444,717
Latest member
melindanegron

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top