ThepExcel Logo
  • บทความ
    • Excel
      • Excel ทั่วไป
      • Excel Pivot Table
      • Excel Power Pivot
      • Power Query
      • Excel Array Formula
      • Excel VBA
      • Excel for Business
      • Excel and Maths
      • ฟังก์ชัน Excel ทั้งหมด
    • Power BI
      • Power Query
      • Data Model
      • DAX Formula
      • Power BI Report
    • Coding
      • Excel VBA
      • Python
      • Power Query M Code
    • Highlights : บทความแนะนำ
    • คลิปวีดีโอ
  • อบรม
    • อบรมลูกค้าองค์กร
    • คอร์สออนไลน์ SkillLane
    • แนะนำวิทยากร
    • Excel/Power BI Skill Map
    • Quiz
  • Shop
    • คอร์สออนไลน์
    • สินค้าทั้งหมด
    • หนังสือเล่ม
    • E-Book
    • Cart
  • Download
    • Download ไฟล์จากเทพเอ็กเซล
    • ThepExcel-Mfx : M Code สำเร็จรูป
    • Date Table สำเร็จรูป
    • กราฟ My Skill
    • github.com/ThepExcel
  • รวม Link
    • รวม Link สอน Excel & Power BI ทั้งไทยและเทศ
    • รวม Link สอน Python / Programming
    • หนังสือแนะนำ
    • Facebook ThepExcel
    • YouTube ThepExcel
    • DAX Formatter
  • Contact
    • แนะนำ เทพเอ็กเซล (Thep Excel)
    • แนะนำวิทยากร : อาจารย์ ศิระ เอกบุตร (ระ)
    • นโยบายการคุ้มครองข้อมูลส่วนบุคคล (Privacy Policy)
  • Facebook
  • YouTube

7 วิธีรับมือกับวันแย่ๆ (ใน Excel)

Categories 📂

Excel ทั่วไป

Tags 🏷️

bad, date, format

อย่างที่ผมเคยย้ำเสมอว่า Excel มองวันที่เป็นแค่ตัวเลขจำนวนธรรมดาตัวหนึ่งที่เปลี่ยนหน้าตาไปเท่านั้น (รายละเอียดอ่านได้ที่นี่)

นอกจากนี้ Excel จะรู้จักวันที่ในรูปแบบที่มันคุ้นเคยเท่านั้น เช่น dd/mm/yyyy หรือ dd-mm-yyyy หรือ yyyy/mm/dd หรือ yyyy-mm-dd (กรณีที่ตั้งค่า Regional Setting ใน Control Panel เป็น Thai )

ดังนั้น ถ้าหากเราใส่วันที่ในรูปแบบที่ Excel ไม่รู้จัก เช่น 2016.12.09 มันก็จะไม่มองว่าเป็นวันที่หรอกนะ นอกจากนี้จะต้องระวังเรื่องการใส่เลขปีด้วย ว่าปกติแล้วควรใส่เป็นปี ค.ศ. เสมอ (ยกเว้นจะตั้งค่าใน Number Format ให้รับ Input เป็น พ.ศ. ไทยไปเลย มีบอกวิธีท้ายบทความ)

แต่บางครั้งเราได้ข้อมูลมาจากคนอื่น (หรือแม้แต่ฐานข้อมูลที่ Office) ซึ่งดันมีข้อมูลวันที่อยู่ในรูปแบบที่แย่ๆ Excel มันก็เลยไม่รู้จัก เราก็เลยต้องยื่นมือไปช่วยหน่อยแล้ววววว!!!

สารบัญ

  • นี่คือ 7 วิธีที่จะรับมือกับวันแย่ๆ ครับ
    • วันแย่แบบที่ 1 : YYYYMMDD โดยปีเป็น ค.ศ.
    • วันแย่แบบที่ 2 : YYYYMMDD โดยปีเป็น พ.ศ.
    • วันแย่แบบที่ 3 : DDMMYYYY โดยปีเป็น ค.ศ.
    • วันแย่แบบที่ 4 : DDMMYYYY โดยปีเป็น พ.ศ.
    • วันแย่แบบที่ 5 : มีสัญลักษณ์ประหลาด เช่น .
    • วันแย่แบบที่ 6 : เลขปีเขียนแบบย่อ จาก YYYY เหลือแค่ YY 2 ตัวหลัง
    • วันแย่แบบที่ 7 : ข้อมูลต้นทางมีหลายรูปแบบผสมผสานกัน!!
    • เทคนิคแถม : คนกรอกข้อมูลดึงดันจะกรอกเป็น พ.ศ.

นี่คือ 7 วิธีที่จะรับมือกับวันแย่ๆ ครับ

สมมติว่ากรอกวันที่แย่ๆ อยู่ในช่อง A1 นะครับ

วันแย่แบบที่ 1 : YYYYMMDD โดยปีเป็น ค.ศ.

วิธีแก้อาการนี้ ทำง่ายๆ ครับ โดยใช้ความรู้เรื่องฟังก์ชั่น TEXT กับ Custom Format มาช่วย ได้ดังนี้

=TEXT(A1,”0000-00-00″)*1 จะได้เป็นตัวเลขที่ถูกต้องแล้ว แต่ถ้าอยากเห็นเป็นวันที่ ก็ให้ Format เป็นวันที่เป็นอันจบ

วันแย่แบบที่ 2 : YYYYMMDD โดยปีเป็น พ.ศ.

วิธีแก้ ผมแนะนำ 2 วิธีแล้วกัน

แบบแรก ตัดทีละส่วนแล้วรวมกันด้วย DATE จะได้ว่า

=DATE(LEFT(A1,4)-543,MID(A1,5,2),RIGHT(A1,2))

แบบที่สอง ใช้ TEXT เหมือนเดิม จะได้ว่า

=TEXT((LEFT(A1,4)-543)&RIGHT(A1,4),”0000-00-00″)*1

วันแย่แบบที่ 3 : DDMMYYYY โดยปีเป็น ค.ศ.

คล้ายกับวิธีที่ 1 ครับ แต่ปรับ Format เล็กน้อย

=TEXT(A1,”00-00-0000″)*1

วันแย่แบบที่ 4 : DDMMYYYY โดยปีเป็น พ.ศ.

คล้ายกับวิธีที่ 2 ครับ มี 2 วิธี

แบบแรก =DATE(RIGHT(A1,4)-543,MID(TEXT(A1,”00000000″),3,2),LEFT(TEXT(A1,”00000000″),2))

แบบที่สอง = TEXT(LEFT(TEXT(A1,”00000000″),4)&RIGHT(A1,4)-543,”00-00-0000″)*1

วันแย่แบบที่ 5 : มีสัญลักษณ์ประหลาด เช่น .

กรณีเป็น ค.ศ :

วิธีแก้ง่ายมาก ก็แปลงจุด (หรือสัญลักษณ์อะไรก็แล้วแต่) ให้เป็นตัวที่ Excel รู้จักเช่น – ด้วย SUBSTITUTE ก็พอครับ

=SUBSTITUTE(A1,”.”,”-“)*1

กรณีปีเป็น พ.ศ.

หลักการก็คือทำให้ . หายไปก่อนด้วย =SUBSTITUTE(A1,”.”,””) แล้วเอาไปเข้ากรณีวันแย่แบบที่สองครับ ซึ่งจะได้ว่า

=DATE(LEFT(A1,4)-543,MID(SUBSTITUTE(A1,”.”,””),5,2),RIGHT(A1,2))

อีกแบบก็จะได้ว่า

=TEXT((LEFT(A1,4)-543)&RIGHT(SUBSTITUTE(A1,”.”,””),4),”0000-00-00″)*1

วันแย่แบบที่ 6 : เลขปีเขียนแบบย่อ จาก YYYY เหลือแค่ YY 2 ตัวหลัง

เช่น DDMMYY โดยปีเป็น ค.ศ. แบบนี้เราก็ต้องรู้ก่อนว่า ปีเป็น 19YY หรือ 20YY

ถ้ามั่นใจว่าเป็น 20YY ก็ทำแค่นี้พอ =TEXT(A1,”00-00-00″)*1

แต่ถ้าเป็น 19YY ก็อาจจะต้องเติมตัวเลข 19 ให้มัน เช่น =DATE(“19″&RIGHT(A1,2),MID(TEXT(A1,”000000″),3,2),LEFT(TEXT(A1,”000000”),2))

วันแย่แบบที่ 7 : ข้อมูลต้นทางมีหลายรูปแบบผสมผสานกัน!!

แบบนี้ ถ้าคิดว่ามีเครือ่งหมายประหลาดอะไรก็แนะนำว่าให้ใช้ SUBSTITUTE ตัดทิ้งให้หมดก่อน

หลังจากนั้นคุณต้องเขียนสูตรเพื่อตรวจเช็ครูปแบบแล้วล่ะ
เช่น ใช้ LEFT RIGHT เช็คดูว่าเลขน่าจะเป็น ค.ศ. หรือ พ.ศ.? และมีกี่ตัวอักษร??

จากนั้นค่อยเอาไปใช้ IF หรือ CHOOSE เพื่อเลือกสูตรที่เหมาะสมต่อไป

แต่ถ้าเกิดเหตุการณ์แบบนี้จริงๆ ไปแก้ตั้งแต่ต้นเหตุดีกว่า ว่าทำไมถึงกรอกข้อมูลได้มั่วขนาดนี้!!!!

อย่างน้อยก็ควรใส่ Data Validation ไว้บ้างนะครับ เช่น

data-validation

เทคนิคแถม : คนกรอกข้อมูลดึงดันจะกรอกเป็น พ.ศ.

อย่างที่บอกว่าเราควรกรอกข้อมูลเป็น ค.ศ. เสมอ แต่ถ้าคนกรอกดึงดันว่าจะกรอก พ.ศ.ล่ะ !!?

วิธีที่ทำให้กรอกข้อมูลเป็น พ.ศ. แล้วข้อมูลไม่เพี้ยน คือต้องเลือก Cell ช่องนั้นๆ แล้วเลือก Number Format ดังนี้ครับ

7 วิธีรับมือกับวันแย่ๆ (ใน Excel)

เป็นอย่างไรกันบ้างครับ กับเทคนิคการรับมือกันวันแย่ๆ ใน Excel ผมหวังว่าจะเป็นประโยชน์กับเพื่อนๆ นะครับ

หากใครมีเทคนิคอื่นๆ ในการจัดการกับปัญหาเรื่องวันที่ อย่าลืมแชร์กันให้ผมและเพื่อนๆ รู้บ้างนะครับ เพราะปัญหาหนึ่งๆ มันมีหลายทางแก้ไขแน่นอน ^^

แชร์ความรู้ให้เพื่อนๆ ของคุณ
13    
13    

ติดตามเทพเอ็กเซล

  • Facebook
  • YouTube

อบรมกับเทพเอ็กเซล

คอร์สออนไลน์ เทพเอ็กเซล
คอร์สออนไลน์ จากเทพเอ็กเซล ดูกี่รอบก็ได้
อบรม Excel / Power BI ให้องค์กรของคุณ

บทความล่าสุด

  • การทำ Simulation ด้วย Excel
  • แกะเคล็ดวิชา Excel Wizard ในการแข่ง Speed Run Excel ระดับโลก
  • เจาะลึก CALCULATE ใน DAX แบบลึกสุดใจ : Part 2
  • วิธีใช้ Power Query ดึงข้อมูล EMS Tracking จากไปรษณีย์ไทย ผ่าน Web API
  • เจาะลึก CALCULATE ใน DAX แบบลึกสุดใจ : Part 1
  • Series สอนดึงข้อมูลจากเว็บ ด้วย Power Automate Desktop
  • ทำความเข้าใจวิธีสั่ง MidJourney แบบละเอียด เพื่อให้ได้ผลลัพธ์ตรงใจ (มากขึ้น)

บทความแนะนำ

🔥ฟังก์ชันทั้งหมดใน Excel 🔥

  • แกะเคล็ดวิชา Excel Wizard ในการแข่ง Speed Run Excel ระดับโลก
  • เจาะลึก CALCULATE ใน DAX แบบลึกสุดใจ : Part 1
  • Series สอนดึงข้อมูลจากเว็บ ด้วย Power Automate Desktop
  • สรุปการใช้ LAMBDA ฟังก์ชันที่ใช้สร้างฟังก์ชันใน Excel 365 และผองเพื่อน
  • วิธีใช้ Excel คำนวณระยะเวลาการทำงานรวม แถมระบุเวลาพักได้แบบยืดหยุ่น
  • วิธีจัดการข้อมูลแย่ๆ ด้วย Power Query ทั้งข้อมูลปนกัน ข้อมูลอยู่บนหัวตาราง
  • แยกข้อมูลที่อยู่สุดเน่า ด้วย Excel Power Query

Categories

Tags

collection concepts copy database Data Model data table data validation date dax dropdown error excel filter finance find format formula function game graph IF index intro iterative len link logic lookup match m code merge mid overview paste pivot power query project row sort speed split substitute table text textjoin time tips trim vba vlookup

Archives

  • January 2023 (1)
  • October 2022 (1)
  • September 2022 (3)
  • August 2022 (3)
  • July 2022 (1)
  • June 2022 (3)
  • May 2022 (1)
  • April 2022 (2)
  • February 2022 (1)
  • December 2021 (2)
  • November 2021 (10)
  • September 2021 (2)
  • August 2021 (6)
  • July 2021 (2)
  • June 2021 (2)
  • May 2021 (10)
  • April 2021 (3)
  • March 2021 (3)
  • February 2021 (4)
  • January 2021 (8)
  • December 2020 (5)
  • November 2020 (13)
  • October 2020 (5)
  • September 2020 (11)
  • August 2020 (4)
  • July 2020 (13)
  • June 2020 (17)
  • May 2020 (16)
  • April 2020 (16)
  • March 2020 (10)
  • February 2020 (15)
  • January 2020 (16)
  • December 2019 (4)
  • November 2019 (3)
  • October 2019 (9)
  • September 2019 (1)
  • August 2019 (7)
  • June 2019 (3)
  • May 2019 (9)
  • April 2019 (9)
  • March 2019 (2)
  • February 2018 (1)
  • January 2018 (3)
  • November 2017 (3)
  • August 2017 (1)
  • July 2017 (1)
  • June 2017 (1)
  • May 2017 (6)
  • April 2017 (6)
  • March 2017 (7)
  • February 2017 (1)
  • January 2017 (2)
  • December 2016 (1)
  • October 2016 (2)
  • September 2016 (3)
  • August 2016 (2)
  • July 2016 (2)
  • June 2016 (1)
  • May 2016 (1)
  • April 2016 (1)
  • March 2016 (2)
  • February 2016 (1)
  • January 2016 (2)
  • December 2015 (2)
  • November 2015 (5)
  • October 2015 (3)
  • June 2015 (2)
  • May 2015 (1)
  • April 2015 (26)
  • January 2015 (1)
  • December 2014 (1)
  • November 2014 (2)
  • October 2014 (1)
  • September 2014 (2)
  • August 2014 (1)
  • June 2014 (1)
  • May 2014 (1)
  • April 2014 (3)
  • March 2014 (3)
  • February 2014 (12)
  • January 2014 (7)
  • December 2013 (2)
  • November 2013 (8)
  • October 2013 (2)

เทพเอ็กเซล : Thep Excel

copyright © 2022

  • Facebook
  • YouTube
เว็บไซต์นี้ใช้คุกกี้ (Cookies)
บริษัท เทพเอ็กเซล จำกัด ให้ความสำคัญต่อข้อมูลส่วนบุคคลของท่าน เพื่อการพัฒนาและปรับปรุงเว็บไซต์รวมถึงสินค้าและบริการต่างๆ หากท่านใช้บริการเว็บไซต์นี้ โดยไม่มีการปรับตั้งค่าใดๆ แสดงว่าท่านยินยอมที่จะรับคุกกี้บนเว็บไซต์ และนโยบายสิทธิส่วนบุคคลของเรา
ตั้งค่าคุกกี้ยอมรับทั้งหมดอ่านเพิ่มเติม
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT