Tim125 225 Getting Started in Visual Basic
Tim125 225 Getting Started in Visual Basic
Table of Contents
Visual Basic Related Questions ............................................................. 1
1 2 3 4 5 6 Where can I find useful Visual Basic tutorials? .............................................................. 1 How do I open the Visual Basic Editor in Excel? ............................................................... 1 How to I program in the Visual Basic Editor .................................................................. 1 How do I reference a cell in a workbook? ....................................................................... 2 How do I link a cell between two different Worksheets? ............................................... 2 How do I use Solver to perform an optimization? .......................................................... 3
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
http://www.anthony-vba.kefra.com/vba/vbabasic1.htm A very basic introduction that provides a good overview to using Visual Basic in Excel. Tutorial 2: Programming In Excel VBA - An Introduction http://www.jlathamsite.com/Teach/VBA/ProgrammingInExcelVBA_AnIntroduction.pdf Another Introduction to VBA programming.
To start using Visual Basic open the Menu: Tools (Excel 2007) or Developer Tab (Excel 2010) Macro Visual Basic Editor. If the Developer Tab is not visible in the ribbon, follow the instructions here: http://msdn.microsoft.com/en-us/library/bb608625.aspx
Page 1
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel Once you open the Visual Basic Editor, shown in Figure 3, on the left is the Project Browser. This has the different components of the program.
To add a macro, double click on the sheet or workbook you wish to modify within the project browser window and a new module will open on the right side to enter your program code.
To run this program go to the Run menu on the top menu bar and click on the Run Sub/UserForm (or you can click F5 on the keyboard). Page 1
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
The program will display the phrase Hello World in a dialog box that pops up.
Page 2
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Page 3
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Page 4
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Buttons are created on a Form to allow the user to select the different forecasting method.
A form is created to allow the user to enter the numeric values for the number of periods and the smoothing constants for Alpha. Page 5
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Simple, but clean, formatting for the Demand Forecasting output of the data.
Page 6
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Cell formatting, colors, buttons, and auto-generated graphs. However, can you spot what is right, and wrong, with the Quarterly Demand graph plots shown above?
Page 7
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Example of a integerated main GUI control panel for Demand Forecasting, and the Inventory Management, Facilities Management, and the Transportation management. Page 8
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
BUTTON [1]: Upon Button click, the screen auto fits to the current maximize screen size. BUTTON [2]: Upon Button Click, this button will print the entire Current Worksheet containing the results of the STEP 1, 2, 3 and 4. BUTTON [3]: Upon Button click, a screen will open to allow the user to enter 24 months of Monthly Demand Data and the parameters of the Forecasting coefficients. BUTTON [4]: Upon Button Click, the software will perform calculations based on the program code written. The results will be displayed in the Summary Results to the right with the Best Model determined by the Month 24 MAPE. The resulting demand will be displayed for the best model presented. BUTTON [5]: Upon Button Click, this group of buttons will open and display the actual Excel Worksheets for each of the: Static. Each open sheet will also have an option to the return back to the MAIN or PRINT the selected sheet. BUTTON [6]: Upon Button Click, this group of buttons will open and display the actual Excel Worksheets for each of: Moving Average. Each open sheet will also have an option to the return back to the MAIN or PRINT. BUTTON [7]: Upon Button Click, this group of buttons will open and display the actual Excel Worksheets for each of the: Exponential. Each open sheet will also have an option to the return back to the MAIN or PRINT.. BUTTON [8]: Upon Button Click, this group of buttons will open and display the actual Excel Worksheets for each of the: Holt. Each open sheet will also have an option to the return back to the MAIN or PRINT. BUTTON [9]: Upon Button Click, this group of buttons will open and display the actual Excel Worksheets for each of: Winters. Each open sheet will also have an option to the return back to the MAIN or PRINT. BUTTON [10]: Upon Button Click, this button will open the MS Excel worksheet that displays a complete summary of all the Forecasting techniques in one a page summary. On this opened sheet are available the option to the return back to the MAIN or PRINT. BUTTON [11]: Upon Button Click, this button will open the MS Excel worksheet that displays a complete summary of all the Forecasting techniques in one a page summary. BUTTON [12]: Upon Button Click, this button will open the MS Excel worksheet that has been determined to be the Optimal (Best) based on the lowest MAPE comparison. BUTTON [13]: Upon Button Click, this button will clear the current data in the Demand Summary Results BUTTON [14]: This is a ListBox selector. Upon Click on each list item, the Model Selected will be updated in the Summary Results: Model Selected cell. Though the Best Model has been calculated (STEP 1), this feature gives the user the ability to choose different Forecasting methods and experiment with the Inventory Management results. BUTTON [19]: This is a data entry cell for whole numbers. The data entry should be for the Standard Deviation of the Weekly Demand. It is used to calculate the Safety Stock Inventory. Hit enter after typing in the value. BUTTON [15]: This is a data entry cell for whole numbers in percentage format. The data entry should be the Holding Cost in terms of a percentage value. Hit enter after typing in the value. BUTTON [16]: This is a data entry cell for the Per Unit Cost in dollars. Enter a dollar value. Hit enter after typing in the value. BUTTON [17]: This is a data entry cell for the Common Order Cost ($) for each order. Enter a dollar value. Hit enter after typing in the value. BUTTON [18]: This is a data entry cell for the CSL (%). Enter a percentage to represented the service level needed. Hit enter after typing in the value. BUTTON [19]: This is a data entry cell for the Lead Time (weeks) Enter a whole number value. Hit enter after typing in the value.
Page 9
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
BUTTON [20]: Upon Button Click, this button will compute all the variables based on the selected Forecasting method for the Inventory Management and display the results in the Summary table. To change the results, change a variable or choose a different an alternative forecasting method and click on Compute Inventory again. BUTTON [21]: Upon Button Click, this button will clear the entire of Inventory Summary results BUTTON [22]: Upon Button Click, this button will navigate to another worksheet to enter all the data and parameters needed for the Facilities Design computations. BUTTON [23]: Upon Button Click, this button will automate the computation of Facilities design utilizing Solver Program for the optimization and will update the screen draw of the network. BUTTON [24]: Upon Button Click, will open the with automatically generate a Network Design figure. BUTTON [25]: Upon Button Click, this button will open the worksheet with the data results for the entire optimization of the Facilities design.. BUTTON [26]: Upon Button Click, will launch Risk Solver Platform for Monte Carlo Simulation analysis BUTTON [27]: Upon Button Click, this button will clear the entire of Facilities Summary results BUTTON [28]: Upon Button Click, this button will compute optimal Transportation results. BUTTON [29]: Upon Button Click, open the Transportation management BUTTON [30]: Upon Button Click, this button will clear the Transportation Management results.
Page 10
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Winters
Year
Demand D1
160.00 140.00
Demand (Qty)
18000
16000
14000 10000
Demand (Qty)
2350 1837 2512 7369 3614 2243 3559 7156 4020 2866 2656 8353 5591 4482 4415 12135 5748 3796 4943 13197
102842 5142.1 13197 1837
120.00
12000 8000
6000
HOLTS COEFFICIENTS alpha 0.10 beta 0.10 WINTERS COEFFICIENTS alpha 0.10 beta 0.10 gamma 0.10
MA Forecast Chart
4000
2000
2000 0 0 10
Period (Qtrs)
Demand: Holt's Method 5 Year Plot with 2 Year Forecast
Actual Demand Forecasted (Holt's Method) Demand 16000
14000
0 20 30
10
Period (Qtrs)
20
30
10000
8000 6000
12000
10000
8000
6000
4000 2000 0
0 5 10 15 20 25 30
MAIN
4000 2000
0
0 0 5 10 15 Period (Qtrs) 20 25 30
Period (Qtrs)
10
15 Period (Qtrs)
20
25
30
In the example, shown in Figure 13, you can see that the smoothing coefficients are adjustable using the scroll bar Form control. Additionally, the miniaturized charts for each forecasting method are presented in a Dashboard Cockpit on the right side for immediate visual inspection upon adjustment of the Data or the smoothing coefficient. By presenting the Dashboard cockpit of the linked Charts, it helps to ensure the smoothing coefficients are optimal. Buttons are also added that link the worksheet to other worksheets for more expedient maneuvering between the worksheets and full-page charts.
Page 11
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
In Figure 14 is shown an example of a Full-Page Chart for the Static Forecasting result. Notice that the horizontal and vertical axes are both labeled. The data series are plotted with different types of markers (squares vs dots), the legend is clearly labeled to which plot is Actual vs Forecasted, the Chart Title is descriptive and in the top left and right hands sides, are buttons that provide direct links to the rest of the workbook. Additionally, an on-screen PRINT button is provided, as well as a Save Chart (as picture) is provided. To export this Chart into Microsoft Word, you can follow this procedure: 1. Click on the Outer Edge of the Chart, so that the entire Chart is selected. 2. Select COPY 3. Open MS Word. 4. Then Paste Special. Select Bitmap or JPEG or PNG as the past option. There are more options for bringing the Chart into MS Word (and Powerpoint), but this provides a basic approach that prints well and easy to use. You can search online for more advanced graphic editing approaches between Excel and Word (and Powerpoint). If you just copy and paste from Excel to Word, you will not allows get clean formatting. Therefore, try to select a Picture type of format (e.g., Bitmap, JPEG, PNG) Also, remember to Label the Figure (i.e., Figure #: Title) and then explain this Figure. Page 12
TIM-125/225: MOT II Supply Chain Management Getting Started with Visual Basic in Excel
Page 13