You are on page 1of 88

MACRO MS EXCEL 2007

Instructor: Chalaivate Pipatpannawong


chalaivate@9expert.co.th
Facebook.com/Chalaivate
http://www.9Expert.co.th
http://www.9ExpertTraining.com
Published : 7 October 2010

Facebook.com/9ExpertTraining
อ.ชไลเวท พิพฒ
ั พรรณวงศ์
E-Mail : chalaivate@9expert.co.th
Facebook : Facebook.com/Chalaivate
• ปัจจุบนั เป็ น อาจารย์ 9EXPERT และ ม.เทคโนโลยีมหานคร
• ที่ปรึกษา ระบบงานด้าน IT และ Training
• มีประสบการณ์ด้านการสอน งานเขียน และการใช้งาน Microsoft Excel มากว่า 10 ปี
• ได้รบั Certified จาก Microsoft อาทิ MCT, MCAS, MOS, MCP
• มีประสบการณ์การสอนให้กบั หน่ วยงานต่าง ๆ ทัง้ ภาครัฐและเอกชน
o กระทรวงเทคโนโลยีสารสนเทศและการสื่อสาร
o จุฬาลงกรณ์ มหาวิทยาลัย
o มหาวิทยาลัยธรรมศาสตร์
o กรมสรรพากร
o … http://www.9ExpertTraining.com
Facebook.com/9ExpertTraining
ข่าวสารประชาสัมพันธ์ เทคนิค ต่าง ๆ พร้อม คลิปจากวิทยากร 9EXPERT

http://www.9ExpertTraining.com 3
กลุ่มนักพัฒนาเว็บไซต์ที่ทกุ คนเข้าถึงได้

http://www.9ExpertTraining.com
9EXPERT Channel – www.youtube.com/9expert
VDO การสัมมนา อบรม และ คลิปเทคนิค จากวิทยากร 9EXPERT

http://www.9ExpertTraining.com 5
www.9ExpertTraining.com
9ExpertTraining – Professional IT Training Site

http://www.9ExpertTraining.com 6
www.9Expert.co.th
9EXPERT CORPORATION Site

http://www.9ExpertTraining.com 7
Macro MS Excel 2007
[MOS 001-3]

• หัวข้อการอบรม
o Review Microsoft Excel 2007 / Formula
o Advanced Featured in Microsoft Excel 
o มาโคร (Macro)
o Creating Macro
o Visual Basic for Application (VBA)
o การนำเข้ าและส่งออกข้ อมูล (Importing and Exporting Data)
o การกำหนดค่าการรักษาความปลอดภัย (Security)
o Case Study
 การ Import Data ของการรายการขาย เพื่อสรุปข้ อมูลในรูปแบบ Pivot Table / Pivot Chart
 การทำ Slip เงินเดือน อัตโนมัติ
 เทคนิคการทำให้ ระบบงานมีความยืดหยุ่น (Flexible)

http://www.9ExpertTraining.com
พร้ อมหรือยังครับ ?

http://www.9ExpertTraining.com
ส่วนประกอบในการทำงาน Excel 2007

http://www.9ExpertTraining.com 10
Workbook & Worksheet

1 The Workbook
The Worksheet
2

http://www.9ExpertTraining.com
Shortcut Key
Ctrl+Z Undo
Ctrl+C Copy,
Enter, Paste,
Ctrl+V Multiple Paste,
Ctrl+X Cut
Ctrl+F, Find,
Ctrl+H Find&Replace
Ctrl+P, Print,
Ctrl+S, Ctrl+F4, Alt+F4 Save, Close, Close Excel
Ctrl+Arrow Move to edge of region
Ctrl+* , Ctrl + Shift + Space Select current region
Ctrl+A Select all cells
Ctrl+Home Select A1,
Ctrl+End Select last cell in used range
Ctrl+Shift+End Select from active cell to last cell in used range.

http://www.9ExpertTraining.com 12
Shortcut Key
Ctrl+Shift+Home Select from active cell to A1
Ctrl+Page Down Move to the next sheet,
Ctrl+Page Up Move to the previous sheet
Ctrl+N Open new workbook
Shift+F11 Insert new worksheet
Shift+F3 Paste function window
=+FunctionName+Ctrl+A Insert new function
Alt+F11 Open VBE
Ctrl+Shift+Enter Array formula
Ctrl+F3, F3 Define name, Paste name
Ctrl+Spacebar Select columns
Shift+Spacebar Select rows
Ctrl+1, Format cells,
Ctrl+B, Ctrl+U Bold, Underline
Ctrl+; , Ctrl+shift+: Current date, Current time

http://www.9ExpertTraining.com 13
การจัดรูปแบบ Cell (Format Cells)

• ขั้นตอนในการจัดมีดังต่อไปนี้
o เลือก Cell ที่ต้องการจัดรูปแบบ
o เข้ าคำสั่งการจัดรูปแบบเซลล์ (Format Cells…)

http://www.9ExpertTraining.com
Condition Formatting (P.110)

ใช้ สำหรับการจัดรูปแบบ อย่างมีเงื่อนไข


Steps
 เลือก Cells
 Home > Conditional Formatting

http://www.9ExpertTraining.com
Conditional Formatting

http://www.9ExpertTraining.com
การใส่ข้อคิดเห็น
• หากต้ องการพิมพ์ข้อความเพิ่มเติมโดยไม่ส่งผลกระทบกับงานเดิม โดยเป็ น
ลักษณะของการโน้ ต หรือคอมเม้ นต์ ข้ อความเพื่อคราวหลังมาดูกเ็ ป็ นการ
เตือนความจำ ใน MS Excel สามารถทำได้ ดังนี้
 คลิกเม้ าส์ปุ่มขวาที่ Cell นั้น
 เลือกคำสั่ง Insert Comment
 พิมพ์ข้อความอธิบาย หรือโน้ ตเก็บไว้

http://www.9ExpertTraining.com 17
การแทรก Worksheet
• โดยปกติใน 1 Workbook จะมีด้วยกัน 3 Worksheet แต่เมื่อคุณ
ทำงานในลักษณะงานที่ใหญ่หรือมีความซับซ้ อนมาก อาจจะมีความ
ต้ องการ Worksheet มากขึ้นซึ่งขั้นตอนของการเพิ่ม Worksheet
ทำได้ ดังนี้
o ป้ าย Home > Insert
o เลือก Insert Sheet

http://www.9ExpertTraining.com 18
Excel Options

http://www.9ExpertTraining.com
Excel Options

http://www.9ExpertTraining.com
การสร้าง Chart

1 Select the data that you want to chart, including the


column titles (January, February, March) and the row
labels (the salesperson names).
Click the Insert tab, and in the Charts group, click the
2
Column button.

http://www.9ExpertTraining.com 21
การสร้าง Chart

http://www.9ExpertTraining.com 22
การคำนวณใน MS Excel
• เริม
่ ต้นการคำนวณ
• การคำนวณคุณสามารถเริ่มต้ นการคำนวณ ด้ วย เครื่องหมาย
เท่ากับ(=) หรือเครื่องหมาย บวก(+) เช่นหากต้ องการ
ทำการบวกเลข 2 กับ 5 ก็สามารถทำได้ โดยการพิมพ์ว่า =2
+5 แล้ วกดปุ่ ม Enter หรือใช้ Arrow Key หรือกด Tab ก็ได้
เช่นกัน

http://www.9ExpertTraining.com 23
ตัวดำเนินการ (Operation)
ตัวดำเนินการเลขคณิต ความหมาย (ตัวอย่าง)
+ (บวก) การบวก (3+3)
- (ลบ) การลบ (3–1) นิเสธ (–1)
* (Asterisk) การคูณ (3*3)
/ (Slash) การหาร (3/3)
% (Percent) เปอร์เซ็นต์ (20%)
^ (เครื่องหมายหมวก) เลขชี้กำลัง (3^2)
& (เชื่อมต่อข้อความ) “Firstname” & “Lastname”

24
ตัวดำเนินการเปรียบเทียบ(Comparison)
• ใน MS Excel คุณสามารถเปรียบเทียบค่าสองค่าด้ วยตัวดำเนินการต่อไปนี้ โดยผลลัพธ์จาก
การเปรียบเทียบด้ วยตัวดำเนินการเหล่านี้มีค่าเป็ นตรรกะ TRUE หรือ FALSE

ตัวดำเนินการเปรียบเทียบ ความหมาย (ตัวอย่าง)


= (เครื่องหมายเท่ากับ) เท่ากับ (A1=B1)
> (เครื่องหมายมากกว่า) มากกว่า (A1>B1)
< (เครื่องหมายน้ อยกว่า) น้ อยกว่า (A1<B1)
>= (เครื่องหมายมากกว่าหรือเท่ากับ) มากกว่าหรือเท่ากับ (A1>=B1)
<= (เครื่องหมายน้ อยกว่าหรือเท่ากับ) น้ อยกว่าหรือเท่ากับ (A1<=B1)
<> (เครื่องหมายไม่เท่ากับ) ไม่เท่ากับ (A1<>B1)

http://www.9ExpertTraining.com 25
Function
• การใส่ฟังก์ชนั
o การใส่ฟังก์ช้ันมีข้นั ตอนดังนี้
o คลิกที่ป้าย Formulas
o คลิกที่คำสั่ง Insert Function…

http://www.9ExpertTraining.com 26
Function
/ Argument

http://www.9ExpertTraining.com 27
Formula
• Round >> ปั ดเศษ
• Sum >> หาค่าผลรวมของช่วงเซล • RoundUp >> ปั ดเศษขึ้ น
• Average >>หาค่าเฉลีย่ • RoundDown >> ปั ดเศษทิ้ ง
• Count >> นับเซลตัวเลขเท่านั้น • Now() >> แสดงวันที่ และเวลา
• CountA >> นับเซลตัวเลข ตัวอักษร ปั จจุบนั
• Max >> หาค่าสูงสุด • Today() >> แสดงเฉพาะวันที่ ปั จจุบนั
• Min >> หาค่าต่ำสุด • DateDif(วันเริม่ ,วันสิ้ นสุด,รูปแบบ)
คำนวณระยะห่างระหว่างวัน 2 วัน
• Bahttext() >> แปลงตัวเลขเป็ น
ข้อความทางการเงิน

http://www.9ExpertTraining.com 28
Expert’s Note

http://www.9ExpertTraining.com
Function การทำงานกับตัวอักษร
• LEN แสดงจำนวนตัวอักษร ของข้ อความ
• UPPER >> แปลงเป็ นตัวอักษรตัวพิมพ์ใหญ่
• LOWER >> แปลงเป็ นตัวอักษรตัวพิมพ์เล็ก

http://www.9ExpertTraining.com 30
Function การทำงานกับวันที่
• Today() >> แสดงวันทีป่ ั จจุบนั
• Now() >> แสดงวันทีแ่ ละเวลาปั จจุบนั
• Year(วันที)่ >> ปี ค.ศ. ของ วันที่ นั้น ๆ
• Month (วันที)่ >> เดือน ของ วันที่ นั้น ๆ
• Day (วันที)่ >> วัน ของ วันที่ นั้น ๆ

http://www.9ExpertTraining.com 31
Function การทำงานกับวันที่

http://www.9ExpertTraining.com 32
Function การทำงานกับตัวอักษร

http://www.9ExpertTraining.com 33
Useful Tools
• Function • Validation
– Condition Function • Pivot Table
– Lookup Function
• Data
– Sort
– Filter
– Sub Total

http://www.9ExpertTraining.com 34
Useful Tools (Cont.)
• Chart • Goal Seek
– Setting Chart • Protection
• Scenario – Protect Sheet
• Auditing Tools – Protect Workbook
• Track Change • Tip & Trick

http://www.9ExpertTraining.com 35
Function

http://www.9ExpertTraining.com 36
Condition Function
• Syntax
• IF(logical_test,value_if_true,value_if_false)

http://www.9ExpertTraining.com 37
Sample IF

= IF ( B2 < 50 , “F” , “P” )

= IF ( B2 < 50 , “F” , IF ( B2 < 80, “P” , “G” ) )

= IF ( B2 < 50 , “F” ,
IF ( B2 < 60 , “D” ,
IF ( B2 < 70 , “C” ,
IF ( B2 < 80 , “B” , “A” )))

http://www.9ExpertTraining.com 38
Condition Function
Start

• ฟังก์ชัน IF ใช้ ในการทำงานกับเงื่อนไข False


Value_if_False Logical_test

• Syntax True

• IF(logical_test,value_if_true,value_if_false)
Value_if_True

End

http://www.9ExpertTraining.com 39
Lookup Function
• ฟังก์ชันเหล่านี้ใช้ ในการค้ นหาค่าที่ต้องการจากตาราง
แบ่งออกเป็ น 3 ฟังก์ชันดังนี้
o LOOKUP(lookup_value,lookup_vector,result_vector)
o HLOOKUP(lookup_value,table_array,row_index_num,range_lookup)
o VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)

http://www.9ExpertTraining.com 40
Lookup Function

http://www.9ExpertTraining.com 41
VLookup Function

http://www.9ExpertTraining.com 42
1 2
P.191

TRUE = ค้นรายการใกล ้เคียง


FALSE = ค้นหาแบบแป๊ ะ ๆ

=VLOOKUP(3,A1:B78,2,FALSE)
Product Name ของ Product ID = 3
ได้ค่า Aniseed Syrup ลำดับ
http://www.9ExpertTraining.com 43
การตัง้ Name สำหรับการคำนวณ

• Naming ใช้ สำหรับการ ตั้งชื่อเพื่อใช้ ในสูตรการคำนวณ


o อ้ างถึงค่าคงที่
o อ้ างถึง Cell
o อ้ างถึง Range
• Tab Formulas
o Define Name

http://www.9ExpertTraining.com
Sub Total
• สำหรับทำการสรุปข้ อมูล แยกตามหมาวดที่ต้องการ
• Data > Sub Total…

http://www.9ExpertTraining.com 45
Validation
• เป็ นเครื่องมือที่ใช้ ช่วยตรวจสอบความถูกต้ องในการป้ อน
ข้ อมูล
• Data > Validation

http://www.9ExpertTraining.com 46
Validation (Cont.)
• หากป้ อนข้ อมูลไม่ถูกต้ องจะแสดง message box
ดังรูป
Tool tip

Message box

http://www.9ExpertTraining.com 47
เทคนิคการทำ List แบบข้าม Worksheet

http://www.9ExpertTraining.com
Work shop # Invoice
เป้าหมายเพือ่ ให้ได้ใช้
• Vlookup()
• Functions
• Trace Formula
• Protect Sheet
• Macro

http://www.9ExpertTraining.com
http://www.9ExpertTraining.com
Home work ส่งมาได้ท่ี Email :
chalaivate@9expert.co.th นะครับ
ใครยังไม่ได้ Add Facebook ก็ท่ี
www.Facebook.com/Chalaivate ครับ

ฝากลองดู Case Study เพิม่ เติม ดูได้ใน


www.9experttraining.com หรือ
www.youtube.com/9expert

http://www.9ExpertTraining.com
Case Study Project Plan
 Download File ประกอบที่
http://www.9experttraining.com/
o Function Max, Min
o Conditional Formatting
o Function IF
o Cell Formatting
o Etc.
Import Data
Import Data
ป้ าย Data > Get External Data
- เลือกว่าจะเอามาจากแหล่งข้อมูลใด
- กำหนดรายละเอียด
Pivot Table & Pivot Chart
อ.ชไลเวท พิพฒั พรรณวงศ์
Chalaivate@9expert.co.th
http://www.facebook.com/chalaivate

http://www.9ExpertTraining.com
Pivot Table
• รายงาน PivotTable คือตารางที่มีการโต้ ตอบที่รวมและ
เปรียบเทียบข้ อมูลจำนวนมากอย่างรวดเร็ว คุณสามารถหมุน
แถวและคอลัมน์เพื่อดูการสรุปที่แตกต่างของข้ อมูลต้ นฉบับ
และคุณสามารถแสดงรายละเอียดของเรื่องที่คุณสนใจได้
• แสดงรายการของตารางที่มีความสัมพันธ์กนั ใน 2 แกน

http://www.9ExpertTraining.com 56
Pivot Table

http://www.9ExpertTraining.com 57
http://www.9ExpertTraining.com 58
Core Concept
 การสรุปข้ อมูลด้ วย Pivot Table คิดให้ ดีว่า เกี่ยวข้ องกับ
Field หรือ Column ใด บ้ าง ?
 ต้ องสรุปอะไร โดยใช้ Column ใด ?
 โดยข้ อมูลดิบต้ องมีข้อมูลเพียงพอ

http://www.9ExpertTraining.com
Pivot Table
ใส่ค่าสำหรับทำสรุป
คอลัมน์
ใส่ค่าสำหรับทำการ
กรองข้ อมูล

ใส่ค่าสำหรับทำสรุป
แถว ใส่ค่าสรุป

http://www.9ExpertTraining.com 60
Pivot Table

http://www.9ExpertTraining.com 61
Pivot Table สรุปยอดสิ นค้าแต่ละ Category
Pivot Table สรุปยอดสิ นค้า
และราคาเฉลี่ย แต่ ละ Supplier
Pivot Chart แสดงยอดขายเป็ นรายเดือน

http://www.9ExpertTraining.com
Pivot Chart และ Pivot Table สรุปยอดขายตาม Country

http://www.9ExpertTraining.com
Macro
่ ่ทำงานอัตโนมัติ เพื่อใช้ทำงานให้รวดเร็ว
เป็ นกลุ่มคำสังที
และเป็ นงานในลักษณะซ้ำ ๆ
การสร้าง ทำได้โดยการบันทึกคำสัง่ (Record)
เช่น การทำระบบอัตโนมัติในการบันทึกข้อมูล
หรือ ออกรายงานซ้ำ ๆ แต่ข้อมูลเปลี่ยนไป

http://www.9ExpertTraining.com 65
Developer Tab
เรียก Developer Tab จาก Excel Options…

http://www.9ExpertTraining.com 66
Create Macro

http://www.9ExpertTraining.com 67
การเก็บ Macro
• Personal Macro Workbook (PERSONAL.XLSB) – จะเก็บ
ไว้ ท่เี ครื่องของตนเอง โดย PERSONAL.XLSB จะเป็ น Workbo
ok ที่ซ่อน อยู่ท่ี
C:\Users\username\AppData\Roaming\Microsoft\Excel\XLSTART\
• New Workbook – สำหรับให้ Workbook ใหม่ท่จี ะเรียกใช้
Macro ได้
• This Workbook – เก็บในเอกสารนี้ โดยจะต้ องบันทึกเป็ นไฟล์
แบบ Macro Enable (*.XLSM)
http://www.9ExpertTraining.com 68
การบันทึกไฟล์ที่มี Macro (*.XLSM)

http://www.9ExpertTraining.com 69
Visual Basic Editor

http://www.9ExpertTraining.com
Debugging

http://www.9ExpertTraining.com
Case Study - Macro

http://www.9ExpertTraining.com
Case Study – การทำ Slip เงินเดือน
• เป็ นรูปแบบสำหรับการ Copy งานไปยังตำแหน่งคงที่

http://www.9ExpertTraining.com
Steps

http://www.9ExpertTraining.com
Case Study - การทำระบบเก็บข้อมูล
• เป็ นตัวอย่างงานสำหรับการใช้ Macro เพื่อทำ Running Number, Copy แบบ Relative

http://www.9ExpertTraining.com
Steps

http://www.9ExpertTraining.com
Case Study – การทำระบบข้อมูล Automation

Input Process Output


(Pivot Table/Pivot
(Raw Data) (Automation) Chart)

http://www.9ExpertTraining.com
Steps

http://www.9ExpertTraining.com
Protection
• เพื่อป้ องกันการเปลี่ยนแปลงแก้ ไขส่วนต่าง ๆ ได้ แก่
o Protect Sheet
o Protect Workbook

http://www.9ExpertTraining.com 79
Protect Sheet
• ป้ องกันไม่ให้ แก้ ไข Worksheet
• Step 1 : Format Cells
o Locked = ไม่ให้ แก้ ไข
o Hidden = ซ่อนสูตร
• Step 2 : Review > Protect Sheet

http://www.9ExpertTraining.com 80
Security
• ป้ องกันไม่ให้ เปิ ดแฟ้ มเอกสาร
• Save As…
• คลิก Tools >
General Options

http://www.9ExpertTraining.com 81
Security
• ป้ องกันไม่ให้ เปิ ดแฟ้ มเอกสาร
• Save As…
• Tools >
General Options...

http://www.9ExpertTraining.com 82
Password
• Password นัน้ ทุกคนรูจ้ กั กันดี ทุกคนใช้ และเชือ่ ว่าทุกคนรูว้ า่ มันมีความสำคัญ แต่ในเมือ่
ทุกๆ คนรู้ แล้วทำอย่างไรกับมัน บางคนจดรหัสผ่าน ติดไว้ทจ่ี อภาพบ้าง ด้านหลัง คียบ์ อร์ด
บ้าง หรือทีห่ นักคือ รหัสผ่าน ตัง้ ชือ่ ว่า “password” เสียเลย เรามาดูกนั ดีกว่าครับ ว่า Passw
ord นัน้ ควรตัง้ อย่างไรกันดี .. โดยควรรูว้ ธิ กี ารขโมย Password หรือ Hack พืน้ ฐานก่อนครับ
• เดาครับ Hacker หรือบุคคลทีต่ อ้ งการเข้าระบบโดยใช้ Password เรานัน้ ขัน้ ต้น ทุกคนต้อง
เดาทัง้ นัน้ ซึง่ Password ทีอ่ ่อนแอ หรือตัง้ ง่าย ๆ เช่น ไม่ใส่อะไรเลย หรือ คำว่า “password”
หรือ ตัง้ ปี พ.ศ.เกิด จะโดนก่อน ครับ … เช่น 1111 , 2222 , 1965 อะไรทำนองนัน้
• ใช้เครือ่ งมือครับ เช่น Tools ต่างๆ ซึง่ ใช้งานดีบา้ งไม่ดบี า้ ง หรือไม่กเ็ ขียนเอง วิธกี ารพืน้ ฐาน
คือ
o ใช้ Dictionary เข้ามาช่วย เพราะโดยส่วนใหญ่ คนทัวไป
่ ๆ อาจตัง้ Password ตามคำทีม่ อี ยูใ่
น Dictionary โดยโปรแกรมก็วนเช็คไปเรือ่ ยๆ ครับ
o หากผ่านขัน้ ตอน 2.1 มาแล้ว แต่ยงั ไม่พบรหัสผ่าน ก็มอี กี วิธคี รับ คือ ไล่เช็ค ทุก ๆ ตัว เช่น หาก
Password 2 หลักก็ aa … az , ….. ไปเรือ่ ย ๆ ครับ
http://www.9ExpertTraining.com 83
คำแนะนำในการตั้ง Password
• ควรตั้ง Password ที่มีความยาวอย่างน้ อย 8 ตัว และมีท้งั ตัวอักษร ตัวเล็ก
ตัวใหญ่ ตัวเลข และอัขระอื่นๆ ประกอบ ๆ กัน โดยที่ไม่ควรเป็ นคำที่อยู่
ใน Dictionary (เพราะหากเป็ นคำอยู่ใน Dict ยิ่งหาเจอง่ายครับ เพียงแค่
ก่อน Run โปรแกรม เอาคำใส Dict มาเปรียบเทียบก่อนเท่านั้น) เพียงเท่า
นี้ คุณก็มีระยะเวลาปลอดภัยพอสมควร อาจถึง 6 เดือน ซึ่งก่อนถึงเวลานั้น
ก็แนะนำให้ คุณเปลี่ยนรหัสใหม่อกี ครั้ง ..
• เพียงเท่านี้ Hacker อาจท้ อใจเลิก ก็เป็ นได้ ครับ

http://www.9ExpertTraining.com 84
Question & Answer

Macro Microsoft Excel 2007 Course

http://www.9ExpertTraining.com 85
More Tips / Case Study

• Project Plan
• Break Event Analysis
• Tips
• Excel Option
• การแยกชื่อ นามสกุล

http://www.9ExpertTraining.com
Evaluation & Survey

1. http://go.9expert.co.th/evaluation
2. http://go.9expert.co.th/survey

1 2

http://www.9ExpertTraining.com
Thank you very much
for your attention

chalaivate@9expert.co.th
www.facebook.com/chalaivate
http://www.9ExpertTraining.com 88

You might also like