情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.

Slides:



Advertisements
Similar presentations
Introduction to Excel This class is “HANDS-ON” you will need to open up an excel spreadsheet and do examples as you go along. Students will be able to.
Advertisements

Mon Week 9 Excel Alice Project Options: – Project of the Stars Submit by Wed 11:59 Week 9, also submit questions RE-SUBMIT for regular deadline – Regular.
Information literacy B Lecture 4 Database and Spreadsheet Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information.
Excel and Visual Basic. Outline Data exchange between Excel and Visual Basic. Programming VB in Excel.
情報基礎 B Lecture 5 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
情報基礎 A Lecture 10 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Basic spreadsheet commands (note on powerpoint) These powerpoint slides were made using the following menu options: View -- normal Insert -- new slide.
Object Oriented Programming A programming concept which views programs as objects with properties and ways to manipulate the object and the properties.
Modeling using VBA. Covered materials -Userforms -Controls -Module -Procedures & Functions -Variables -Scope.
Visual Basic for Applications. What it does Extends the features and built in functions of Excel – Create and run VB procedures – Some may be easy to.
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 5. Part 5  1. Procedures  2. Sub Procedures  3. Function Procedures.
Arrays. What is an Array? An array is a way to structure multiple pieces of data of the same type and have them readily available for multiple operations.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
Adding Automated Functionality to Office Applications.
Introduction to Excel VBA University of Chicago Graduate School of Business Introduction to Computer Based Models Bus Mr. Schrage Spring 2003.
 Excel – Basic Elements  Using Macros  Excel VBA Basics  Excel VBA Advanced.
IE 212: Computational Methods for Industrial Engineering
情報基礎 A Lecture 15 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
12. Visual Basic If Statements and Do Loops. Open 12b-datastart.xlsm.
Introduction on VBA Lab 05 ins.Tahani Al_dweesh. Lab Objectives Introduction Calculation with VBA Storing and Retrieving Variables in a Worksheet Using.
CHAPTER 13 Creating a Workbook Part 2. Learning Objectives Work with cells and ranges Work with formulas and functions Preview and print a workbook 2.
情報基礎 B Lecture 8 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Using Technology to ease the administration burden CAPS Recording Mark Sheets.
More While Loop Examples CS303E: Elements of Computers and Programming.
OV Copyright © 2011 Element K Content LLC. All rights reserved.  Insert Text  Format Text  Sort Data  Duplicate Data  Generate a Report Formatting.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
Count and add list of numbers From user input and from file.
Chapter 16: Programming Structures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
ME 142 Engineering Computation I Using Subroutines Effectively.
Introduction to Excel VBA UNC Charlotte CPE/PDH Series December 17, 2009.
Using Sheets To help with data. Sheets is a spreadsheet program that can interface with forms, docs, or presentations. A spreadsheet program has cells.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
VBA Navigation, Conditionals, and Boxes. VBA Navigation.
Excel Part 2 Beth McKelvey. AutoSum The function in Excel that calculates the sum of a group of numbers.
Excel Basics. Differentiating between worksheets and spreadsheets Differentiating between workbooks and worksheets.
# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Ranges. Unlike many of our programming concepts, the idea of a Range is particular to Excel The ideas and code discussed in these slides can be found.
مقدمة في البرمجة Lecture 7. Write VB.net project using the for loop to calculate : 1- the sum of numbers from 1 to (A) numbers. 2- the sum of Odd numbers.
情報基礎 A Lecture 9 Takeshi Tokuyama ・ Jinhee Chun Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis.
How to Work With SURN Principal Academy Data For data downloaded from onlineobservationtools.com.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Excel Introduction to computers. Excel 2007 Starting the Excel program.
ME 142 Engineering Computation I More Loops & Arrays.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Macros in Excel Using VBA Time Required – 5 hours.
IE 8580 Module 4: DIY Monte Carlo Simulation
VBA - Excel VBA is Visual Basic for Applications
Fall HORT6033 Molecular Plant Breeding
CSC115 Introduction to Computer Programming
Creating a Workbook Part 2
Department Array in Visual Basic
Introduction to computers
Lesson 1 Notes Chapter 6.
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CS150 Introduction to Computer Science 1
Let’s all Repeat Together
do/while Selection Structure
EXCEL How to Hide Columns Using VBA
情報基礎B   Lecture 7 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
情報基礎B   Lecture 6 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information.
Repetition (While Loop) LAB 9
Mean Absolute Deviation
REPETITION Why Repetition?
Presentation transcript:

情報基礎 A Lecture 12 Takeshi Tokuyama Tohoku University Graduate School of Information Sciences System Information Sciences Design and Analysis of Information Systems

Programming VBA Score Data Processing

Preparation

Data Processing –Score Data- Download “hogehoge”

Code in Regular Module Insert -> Regular Module 1 2 Check if you are in data2.xls-[module1] Check if you are in data2.xls-[module1]

Backup your sheet Right Click Sheet “Score” “Score(2)” Backup of Sheet ”Score” 4 5 Backup your sheet in case of programming errors. Those errors might delete your data. You cannot undo executed operations

Sum and average

For - Next For i = 1 to 10 cells( i, 1 ) = i Next i For j = 1 to 10 cells( 1, j ) = j Next j Ex.1 Procedure to enter row number ( Row numbers in A1-A10 ) Ex.2 Procedure to enter column number ( Column numbers in A1-J1 ) Row Operation Column Operation Cells(Row num, Col num) Cells( i, Col num) Put i into row num Column: j Row: i Cells(Row num, Col num) Cells(Row num, j ) Put j into col num

Sum and Average -Japanese- Sum of 100 students for Japanese Data range for loop: B3 to B cells: Row 3 to Row 102 on column B Operation for Rows Sum in B103 Average in B104 Use i for cell number A subject row: i 1Sub sum_ave_japanese() 2 Dim i As Integer 3 Dim sum1 As Integer 4 5 Worksheets(“Score”).Activate 6 sum1 = For i = 3 To sum1 = sum1 + Cells( i, 2 ) 10 Next I ‘Sum B Cells( i, 2 ) = sum1 14 ‘Average B Cells( i + 1, 2 ) = sum1 / End Sub Sheet: Score data2.xls

For – Next(Nesting) Ex.3 Procedure to output “rownum * colnum” on each cell in A1 to J10 Nested loop Cells(Row num, Col num) Cells( i, j ) Put i as row number, j as column number For i = 1 to 10 For j = 1 to 10 cells(i, j) = i * j Next j Next i Column: jRow: i Nest two For ~ Next For j = 1 to 10 For i = 1 to 10 cells(i, j) = i * j Next i Next j Same results, Different order

Sum and Average for each Subject Sub sum_ave_japanese() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 2 ) Next i Cells( i, 2 ) = sum Cells( i + 1, 2) = sum / 100 End Sub Sub sum_ave_english() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 3 ) Next i Cells( i, 3 ) = sum Cells( i + 1, 3) = sum / 100 End Sub Sub sum_ave_math() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 4 ) Next i Cells( i, 4 ) = sum Cells( i + 1, 4) = sum / 100 End Sub Sub sum_ave_history() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 5 ) Next i Cells( i, 5 ) = sum Cells( i + 1, 5) = sum / 100 End Sub Sub sum_ave_chemistry() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 6 ) Next i Cells( i, 6 ) = sum Cells( i + 1, 6) = sum / 100 End Sub Sub sum_ave_science() Dim i As Integer Dim sum As Integer Worksheets(“Score”).Activate sum = 0 For i = 3 To 102 sum = sum + Cells( i, 7 ) Next i Cells( i, 7 ) = sum Cells( i + 1, 7) = sum / 100 End Sub Write a procedure to calculate sum and average for each subject using nested loop. Write a procedure to calculate sum and average for each subject using nested loop. JapaneseEnglishMath History ChemistryScience You can copy and edit for the other subject, but… Sheet: Score data2.xls

Sum and Average for each Subject Nested loop Sheet: Score data2.xls Column: jRow: i Nested loop For j ■ to ■ Next j For i ■ to ■ Next i Calculate sum and average for each subject. Nest structure is below j for column(subject) i for row(student)

Sum and Average for each Subject Nested loop Sheet: Score data2.xls Column: jRow: i Nested loop Be careful when initialize “sum2” 1Sub sum_ave_6sub() 2 Dim i As Integer 3 Dim j As Integer 4 Dim sum2 As Integer 5 Worksheets(“Score”).Activate 6 7 For j = 2 To 7 8 sum2 = 0 9 For i= 3 to sum2 = sum2 + Cells(i, j) 11 Next i 12 ‘Sum B Cells( i, 2 ) = sum1 14 ‘Average B Cells(i+1, 2) = sum1 / Next i 17End Sub

Grading for each subject

Grading for Japanese 15 Output a grade of Japanese for student 1001(Cell B3) into Cell H3 If Cells(3, 2) >= 90 Then Cells(3, 8) = “A" ElseIf Cells(3, 2) >= 80 Then Cells(3, 8) = “B" ElseIf Cells(3, 2) >= 70 Then Cells(3, 8) = “C" ElseIf Cells(3, 2) >= 60 Then Cells(3, 8) = “D" Else Cells(3, 8) = “F" End If Procedure to output grades into H3 to H103 Put “i” in row number to operate Procedure to output grades into H3 to H103 Put “i” in row number to operate

Grading for Japanese data2.xls Sheet: Score ・ Procedure to Output Grades of Japanese for student 1001 to 1100 into H3 to H102 ・ Grading criterion A: if score >= 90 B: if 90 > score >= 80 C: if 80 > score >= 70 D: if 70 > score >= 60 F: if 60 > score Row: i Operation for Rows 1Sub grade_jp() 2 Dim i As Integer 3 Worksheets(“Score”).Activate 4 5 For i = 3 To If Cells(i, 2) >= 90 Then 7 Cells(i, 8) = “A” 8 ElseIf Cells(i, 2) >= 80 Then 9 Cells(i, 8) = “B” 10 ElseIf Cells(i, 2) >= 70 Then 11 Cells(i, 8) = “C” 12 ElseIf Cells(i, 2) >= 60 Then 13 Cells(i, 8) = “D” 14 Else 15 Cells(i, 8) = “F” 16 End If 17 Next i 18End Sub

Grading for each subject 17 Operation Order: Japanesestudent 1001 to 1100 Englishstudent 1001 to 1100 … Sciencestudent 1001 to 1100 Operation Order: Japanesestudent 1001 to 1100 Englishstudent 1001 to 1100 … Sciencestudent 1001 to 1100 Write a procedure to calculate sum and average for each subject using nested loop. Write a procedure to calculate sum and average for each subject using nested loop. Nested loop

Grading each Subject data2.xls Sheet: Score ・ Procedure to Output Grades of each subject for student 1001 to 1100 into H3 to M102 ・ Grading criterion A: if score >= 90 B: if 90 > score >= 80 C: if 80 > score >= 70 D: if 70 > score >= 60 F: if 60 > score Row: i Col: j Nested loop 1Sub grade_6sub() 2 Dim i As Integer 3 Dim j As Integer 4 Worksheets(“Score”).Activate 5 For j = 2 To 7 6 For i = 3 To If Cells(i, 2) >= 90 Then 8 Cells(i, 8) = “A” 9 ElseIf Cells(i, 2) >= 80 Then 10 Cells(i, 8) = “B” 11 ElseIf Cells(i, 2) >= 70 Then 12 Cells(i, 8) = “C” 13 ElseIf Cells(i, 2) >= 60 Then 14 Cells(i, 8) = “D” 15 Else 16 Cells(i, 8) = “F” 17 End If 18 Next i 19 Next j 20End Sub