Computer Science Engineering 1113 Lecture 7 Data Validation
















- Slides: 16

Computer Science & Engineering 1113 Lecture 7 Data Validation, Worksheet Protection, and Macros CSE 1113 Lecture 7 -Data Validation and Macros 1

Data Validation • Controls the type of data or the values input in a cell • Reduces input errors • Multiple criterion can be applied to a cell Display a message dialog box Restrict input to a whole number within limits Restrict input to values in a drop down list Restrict input to a decimal number within limits Restrict input to a certain time frame. (either date, time, or both) Restrict text to a specified length Calculate what is allowed based on the value in another cell Use a formula to calculate what is valid CSE 1113 Lecture 7 -Data Validation and Macros 2

Macro A series of commands and functions that are stored in a Microsoft Visual Basic module • Automates your keystrokes and actions in Excel • Use these when you complete the same tasks repetitively • When you create a macro VBA program code is automatically generated CSE 1113 Lecture 7 -Data Validation and Macros 3

Macro Example Scenario You work for a company that employs people to make customer satisfaction calls for various companies. Your department provides services for all the major auto makers in the U. S. Each employee is assigned a state and it is their job to call each household and conduct a brief survey. You receive a weekly list of customers from each auto company and it is your job to separate the list by state and distribute the list to your employees. Your manager would like the customers stored in an Excel file with each state having its own worksheet. CSE 1113 Lecture 7 -Data Validation and Macros 4

File Sent from Vendor Comma Delimited File, meaning each piece of information is separated by a comma. (Created in Notepad or another text editor. ) • Information can be separated by other characters such as a colon, or tab. • Information can be sent in different formats such as. csv or xml files. CSE 1113 Lecture 7 -Data Validation and Macros 5

Create your Template 1. Create an Excel Workbook named Customers. 2. Create tabs with the names of the States you need. 3. Input information that will not change 4. Copy the worksheet created to all the tabs and change the state name (Follow the slides to complete steps 4 -6) CSE 1113 Lecture 7 -Data Validation and Macros 6

4. Create data validation rules for your spreadsheet CSE 1113 Lecture 7 -Data Validation and Macros 7

Break Down into Separate Macros 1. Macro Name: Unprotect. Worksheets 2. Macro Name: Import. File 1. 2. Delete contents from every worksheet Import information 1. 2. 3. Concatenate phone number Filter Copy/Paste 3. Macro Name: Separate. States 4. Macro Name: Protect. Worksheets Note: Always create a backup first CSE 1113 Lecture 7 -Data Validation and Macros 8

Protect. Worksheet Macro CSE 1113 Lecture 7 -Data Validation and Macros 9

CSE 1113 Lecture 7 -Data Validation and Macros 10

Import. File Macro CSE 1113 Lecture 7 -Data Validation and Macros 11

Separate. States Macro CSE 1113 Lecture 7 -Data Validation and Macros 12

CSE 1113 Lecture 7 -Data Validation and Macros 13

Example of VBA Program Code generated from recording macro Sub Import. File() Range("A 4: H 56"). Selection. Query. Table. Delete Selection. Clear. Contents Range("A 4"). Select With Active. Sheet. Query. Tables. Add(Connection: = _ "TEXT; L: CSE 2111Autumn 2013CSE 2111 Slides AU 2013Lecture 9 -Data Validation and MacrosMacro TestCustomers. txt" _ Step through a macro CSE 1113 Lecture 7 -Data Validation and Macros 14

Assigning Macro to the Quick Access Toolbar 1. File Options Quick Access Toolbar CSE 1113 Lecture 7 -Data Validation and Macros 15

CSE 1113 Lecture 7 -Data Validation and Macros 16