1. Trang chủ
  2. » Công Nghệ Thông Tin

Mastering excel user forms by mark moore

56 75 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 56
Dung lượng 1,77 MB

Nội dung

Table of Contents Title Page Acknowledgments Copyright Using Forms Excel Model Data Structure Form Objects Other Lessons Mastering Excel User Forms Mark Moore Acknowledgments I would like to thank Sharon Deitch for her invaluable help in testing, proofreading and making this information as clear as possible I tend to skip steps here and there Sharon keeps me in line Copyright © 2015 by Mark Moore All rights reserved worldwide No part of this publication may be replicated, redistributed, or given away in any form without the prior written consent of the author/publisher or the terms relayed to you herein User Interface Why should you use a form? Because it gives you more control over data collection By using Excel’s built-in form objects, you can limit what the user can input Forms also give you an alternate way to display options the user can make Your Excel model can then react to the choices made by the user Without forms, user inputs are limited to typing in numbers or text in a cell Using forms gives the user a richer experience You can download the follow along workbook at my website: http://markmoorebooks.com/userforms/ You will need to sign up and the click on the link in the confirmation email Then you will receive an email with the workbooks attached Emails might get caught in your Spam folder so make sure you check it if you don’t get the email within a few minutes Adding Forms All the form objects are located on the Developer tab If you not have the Developer tab visible, the following (in Excel 2013): – On the File tab, click Options – In the Excel Options dialog box, click on Customize Ribbon - In the window on the right, select Developer To show the Developer tab in Excel 2007: Click the Office button, and then click Excel Options Click Popular at the top of the left window, and then click Show Developer Tab in the Ribbon Click Insert, and you will see this box appear in the Ribbon: Form Controls vs ActiveX Controls You’ll notice that the drop-down box has two sections, Form Controls and ActiveX controls Form Controls are built into Excel They are backwards compatible to Excel You can use form controls with or without macros They are simple to use and can meet most of regular Excel users’ needs ActiveX Controls are based on the ActiveX technology (developed by Microsoft) These controls are loaded by Excel and have much more flexibility than the Form Controls (you can control just about anything on an ActiveX Control, font style, font color, etc.) However, ActiveX Controls have a few drawbacks Some ActiveX Controls cannot be used directly on a worksheet but rather need a custom form (we will cover this later) Many computers will not allow ActiveX to run natively, so you will have to add the file to the Trusted Sites (even then the IT department might not allow it) Lastly, they can be unstable and crash unexpectedly Therefore, for the rest of the lesson, you will be using Form Controls Using Forms To really understand how to use forms, you are going to use the sample data in the follow along workbook to build several mini-dashboards Each dashboard uses one form component, so you can get experience with each object I build dashboards a particular way that leverages Excel’s ability to extract data from a database I explained this topic in detail in the Mastering Excel: Pivot Tables lesson If you have not read that lesson or it’s been a while since you read it, here’s a quick review Excel Model Data Structure To leverage your time and make your Excel model as flexible as possible, you should think of building your model with three distinct layers Data Layer This is the foundation of your reports This is an extract from Great Plains, Oracle, SAP, or whatever system you use Each field needs to have a title and must contain similar data For example, if the column has a title of Name, the entire column needs to have names in it Don’t stick someone’s employee ID in there Add another column for Employee ID It makes no sense to ‘save’ a column Excel doesn’t care and you have 16,000 columns, use as many as you need The data will end at the first completely empty row and the first completely empty column Do not add empty rows to make the data more readable Data is not supposed to be readable It is simply used to store random facts Your reports are what needs to be readable Here is a screen shot of a sample data layer: Report Layer This is the layer that everyone sees It has the charts, Pivot Table, reports, pretty colors, logos, etc You make this one shine and look great This is the layer that gets printed and displayed in presentations Business Logic This is what ties together the Data layer and the Report layer These are the formulas, charts, and other calculations that extract data from the data layer and convert it into information The layers are what is called ‘loosely coupled’ This means that although they communicate with each other, you can change one layer without affecting the other For example, you won’t have to rebuild your entire model when a new field is added to the data layer How forms fit in? Forms live in the Report layer They allow your users to have some decisionmaking capabilities to change the information For example, if you built a report that showed January results that would only work for a person that wanted to see January data You would have to build another report to show February data At the end of the year you would end up with 12 reports Instead, I suggest you build a report that allows the users to choose which month they want to see One report now can be sent to 12 people, each of whom wants to see a different month With a little bit of advance planning, you have increased the efficiency of this report 12 times over Make sense? Button The button is the simplest of form objects to use The principal function of the button control is to run a macro by clicking the button Even though this lesson does not go into macros, you can create a button control to see how it works You can download the follow along workbook at my website: http://markmoorebooks.com/userforms/ - Open the Forms.xlsx follow along workbook - Select the Button worksheet – On the Developer tab, click Insert, and then click the button icon under Form Controls Your mouse icon will change to a small cross-hair - Click and drag the cross-hair to create a button When you release the mouse, the Assign macro dialog box appears - Open the Forms.xlsx workbook (if it isn’t open) - Go to the Option Button worksheet - Create two option buttons (Developer Tab > Insert) - Right-click Option Button and select “Edit Text.” - Change the text from Option Button to Invoice Date - Repeat the previous steps to change the text of Option Button to Order Date - Right-click on Invoice Date, and select “Format Control.” 10 - Select the Control tab The Option Button only has two values, Unchecked and Checked Cell link the cell that will store the value of the checked or unchecked Option Button 11 - Click inside the Cell link box and select you guessed it, cell F2 12 - Click OK 13 - Shade cell F2 any color you like to keep track of it 14 - Right-click the Order Date option button, and select “Format Control.” 16 - Select the Control tab, and then click inside whoa the Cell link is already populated? Yes, when you have several option buttons they all inherit the cell link cell of the first one That cell, F2 in your case, will have the number of the option button that was clicked Having the same cell store the value of all the option boxes is how Excel prevents a user from making multiple selections Click each of the option buttons to see how the number changes from to Now you have to put a formula in column D that will retrieve either the Invoice Date or the Order Date based on the value in F2 18 - Select cell D5 19 - Input this formula: =IF($F$2=1,INDEX(Data!$A$2:$A$100,MATCH('Option Button Complete'!B5,Data!$C$2:$C$100,0)),INDEX(Data!$B$2:$B$100,MATCH('Option Button Complete'!B5,Data!$C$2:$C$100,0))) OK, I know it’s a huge formula You don’t have to type it in I put it in a text box in the follow along workbook for you Copy the formula and paste it into cell D5 Then copy the formula to all the other cells Last step is to put an IF statement in cell D4 to have the column title update automatically 20 - Select cell D4 21 - Input this formula: =IF(F2=1,"Invoice Date", "Order Date") Now you have to hide the cell link cell If you want to have the option buttons hide the cell link cell, you have to change their transparency 22 - Right-click the Invoice Date option button and select “Format Control.” 24 - Select the Colors and Lines tab 25 - Change the ‘No Fill’ color to Automatic 26 - Click OK 27 - Do the same to the Order Date option button 28 - Move/Resize the buttons to cover the cell link cell 29 - Optional: Remove the grid lines to give the report a cleaner look Note: What about that HUGE formula? What is INDEX, what it is doing? Look at the Index worksheet in the follow along workbook to learn how it works I know it looks intimidating but it really isn’t Group Box The Group box is a categorization object that you can use to group similar form objects For example, the image below shows four option buttons that have been grouped inside a Group Box with the title Region Group Boxes and Option Buttons interact in a special way Group Boxes change how Option Buttons function Consider this situation (this is in the Group Box worksheet): You want the user to choose one option from (North, South, East, West) and a separate option from (Red, Orange, Yellow, Green, Blue, Indigo, Violet) As you learned in the last section, Option buttons are forms that allow only one choice When you select one, all the others are deselected Try it Select a Region and as soon as you select a Color, the Region will be deselected Additionally, all the Option Buttons will have the same Cell Link cell How can you resolve this? By using the Group Box When a Group Box encloses several option buttons, Excel treats those Option Buttons as a distinct group Users will be able to choose only one option from the group inside the Group Box Each group will have its own Cell Link cell You are going to add to two Group Boxes to separate the Option buttons into two groups - Select the Group Box worksheet - In on the Developer tab, click Insert, and then click the Group Box button - Click and drag the cross-hair to create the Group Box that surrounds the Region option buttons - Right-click the Group Box title, and then select “Edit Text.” - Change the Group Box title to Regions - Create another Group box around the color option buttons, and then change its title to “Colors.” 12 - Right-click the Red Option Button, and then select Format Control 14 - Click inside the Cell link box, and select cell H2 This is tricky!!! The Group Box must enclose the ENTIRE Option button control Look at this: I right clicked the Blue option button but it is not entirely surrounded by the group box This means it is not part of the set I need to resize the group box or the option button so the button fits inside Now I have to change the Cell link to H2 for the Blue, Indigo and Violet option buttons 16 - Make sure the entire option buttons fit inside their respective group boxes (both Regions and Colors) 17 - Change the cell Link for each group (Regions link to F2, Colors link to H2) Sometimes, Excel gets confused If you can’t get the Cell link to stick, delete the Group Box and draw another one Now you should be able to click one region and see the result in cell F2 and then click a color and see the result in cell H2 Labels Labels don’t ‘do’ anything They have no functionality other than to convey information They are similar to comments and text boxes Once you create a Label (following the same steps we have used in a previous exercises) just click inside the label and put whatever text you want in it Labels are very simple, so there is no worksheet for them in the follow along workbook Scroll Bar Scroll bars are everywhere in Windows Scroll bars are the objects you click in Excel, Firefox, and Internet Explorer to page up and down Scroll bars can be positioned horizontally or vertically The Scroll bar worksheet has this report on it You are going to change this report so that users can decide how many customers they want to see - Select the Scroll Box worksheet - In the Developer tab, click Insert, and then click the Scroll Bar button - Click and drag the cross-hair to create a scroll bar (it can be horizontal or vertical) - Right-click the scroll bar control, and then select “Format Control.” - Select the Control tab Most of the items here are self-explanatory The Page change item determines how many pages to scroll down when the gray part of the scroll bar is clicked The Incremental change item determines the increase when the top or bottom arrow is clicked - Fill out the settings per the image below Since you want the users to select a number between and 10, those will be the minimum and maximum values, respectively The page change is so when the user clicks in that area the values will increase by - Click OK 10 - Shade cell F2 any color you like Now you have to connect the report to cell F2 I put the formulas in there for you (cells C5:C14 have the LARGE function in them), all you need to is put an IF statement around the formulas so they interact with cell F2 11 - Select cell B3 (the title), and change its text to ="Top "&F2&" Invoiced Customers" 13 - Select cell B5 The goal is to show the count of customers that are in cell F2 That is the limit; you not want to show any more customers than that To accomplish this, you are going to compare the number in column A to the number in F2 If the column A number > F2, not display anything 14 - Change the formula in cell B5 to this: =IF(A5>$F$2,"",INDEX(Data!E:E,MATCH(ScrollBar!C5,Data!G:G,0))) 15 - Copy the formula down the range to cell B14 16 - Select cell C5 You are going to put the C5 formula inside an identical IF statement 17 - Change the formula in cell C5 to this: =IF(A5>$F$2,"",LARGE(Data!G:G,ScrollBar!A5)) 18 - Copy the formula down to cell C10 Now click the scroll bar and see how the report reacts to the changes 19 - The last step is to hide the cell link cell You can resize the scroll bar and move it over the cell or you can hide the columns It’s your choice Moving and Positioning Controls Having a nice looking form is important to your users However, getting form objects aligned just right is very tedious and time consuming I’m going to show you some Excel tricks to help you get everything positioned easily - Select the Positioning worksheet Notice how the form objects are not aligned correctly Selecting objects: Click and hold the CTRL key while clicking on several objects to select and move them OR In the Home tab, select Find & Select > Selection Pane Clicking on the Selection Pane lets you select any or all objects (use the CTRL key to select multiple objects) You can also hide objects (Just hide, not delete) by clicking the eye icon on the right of the pane If you select and object, then double click it, you can change its Title right in the Selection Pane For example, you can double click Check Box and rename it to Tulips - Select all the Option Buttons A new Format tab appears when you select a form object - Click the Drawing Tools, Format tab - Click the Align button You will see these options: Use these options to get the selected objects precisely aligned Most of the choices are selfexplanatory There are a few that need some clarification Distribute Horizontally/Distribute Vertically - These options not move the top or bottom items Rather, they spread out all the ‘in between’ items so they are evenly spaced out Snap to Grid - If you click this on, when you move an object, it snaps to the nearest grid intersection Snap to Shape - If you click this on, when you move an object, it snaps to the edges of the nearest object Other Lessons Mastering Excel 90 Interview Questions (http://www.amazon.com/dp/B009SZYDOC) Mastering Excel Formula Tips and Tricks (http://www.amazon.com/dp/B00G4USD5E) Mastering Excel Formulas IF, AND, OR (http://www.amazon.com/dp/B009FD7J2K) Mastering Excel Formulas SUM, SUMIF (http://www.amazon.com/dp/B00A9JFER6) Mastering Excel Formulas VLOOKUP (http://www.amazon.com/dp/B009M5F5IG) Mastering Excel: Autofilter, Advanced Autofilter (http://www.amazon.com/dp/B00ASJBZFW) Mastering Excel: Conditional Formatting (http://www.amazon.com/dp/B00K7USCH6) Mastering Excel: MS Query (http://www.amazon.com/dp/B00DT5FH5G) Mastering Excel: Named Ranges, OFFSET and Dynamic Charts (http://www.amazon.com/dp/B00B6I25BW) Mastering Excel: Pivot Tables (http://www.amazon.com/dp/B00C56564M) Mastering Excel: Sharing Workbooks (http://www.amazon.com/dp/B00KVGRI4Y) Mastering Excel Macros: Introduction (http://www.amazon.com/dp/B00O2OOJ7A) Mastering Excel Macros: Introduction (Book 1) (http://www.amazon.com/dp/B00O2OOJ7A) Mastering Excel Macros: Debugging (Book 2) (http://www.amazon.com/dp/B00OE4821W) Mastering Excel Macros: Beginning to Code (Book 3) (http://www.amazon.com/dp/B00PFWDZXC) Mastering Excel Macros: If Statements (Book 4) (http://www.amazon.com/dp/B00QGWP8PI) Mastering Excel Macros: Looping (Book 5) (http://www.amazon.com/dp/B00SCPTJH0) Mastering Excel Macros: Object Variables (Book 6) (http://www.amazon.com/dp/B00TSN7IP0) ... Contents Title Page Acknowledgments Copyright Using Forms Excel Model Data Structure Form Objects Other Lessons Mastering Excel User Forms Mark Moore Acknowledgments I would like to thank Sharon... options the user can make Your Excel model can then react to the choices made by the user Without forms, user inputs are limited to typing in numbers or text in a cell Using forms gives the user a... herein User Interface Why should you use a form? Because it gives you more control over data collection By using Excel s built-in form objects, you can limit what the user can input Forms also

Ngày đăng: 20/03/2018, 09:13