ไปยังเนื้อหาหลัก

วิธีจัดเรียงวันที่อัตโนมัติเมื่อป้อนหรือเปลี่ยนวันที่ใน Excel 

ใน Excel ไฟล์ ประเภท ฟังก์ชันสามารถช่วยคุณจัดเรียงวันที่จากน้อยไปมากหรือมากไปหาน้อยได้ตามที่คุณต้องการ แต่ไม่ใช่แบบไดนามิกหากคุณเรียงวันที่แล้วเพิ่มวันที่ใหม่คุณจะต้องจัดเรียงอีกครั้ง มีวิธีใดที่ดีและรวดเร็วในการจัดเรียงวันที่โดยอัตโนมัติเมื่อป้อนวันที่ใหม่ทุกครั้งในแผ่นงาน

จัดเรียงวันที่อัตโนมัติเมื่อป้อนหรือเปลี่ยนวันที่ด้วยสูตร

จัดเรียงวันที่อัตโนมัติเมื่อป้อนหรือเปลี่ยนวันที่ด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา จัดเรียงวันที่อัตโนมัติเมื่อป้อนหรือเปลี่ยนวันที่ด้วยสูตร

ตัวอย่างเช่นวันที่เดิมในคอลัมน์ A สูตรต่อไปนี้สามารถช่วยให้คุณจัดเรียงวันที่หรือสตริงข้อความอื่น ๆ โดยอัตโนมัติในคอลัมน์ตัวช่วยใหม่ตามคอลัมน์ที่คุณต้องการจัดเรียงโปรดดำเนินการดังนี้:

1. ใส่สูตรนี้:

=INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,"<="&$A$2:$A$15),0)) ลงในเซลล์ว่างข้างคอลัมน์วันที่ของคุณ C2ตัวอย่างเช่นจากนั้นกด Ctrl + Shift + Enter คีย์เข้าด้วยกันและคุณจะได้ลำดับตัวเลขจากนั้นลากที่จับเติมลงไปที่เซลล์ที่คุณต้องการใช้ดูภาพหน้าจอ:

หมายเหตุ: ในสูตรข้างต้น: A2: A15 คือช่วงวันที่เดิมของคุณที่คุณต้องการจัดเรียงอัตโนมัติ

จัดเรียงเอกสารอัตโนมัติตามวันที่ 1

2. จากนั้นจัดรูปแบบตัวเลขเป็นรูปแบบวันที่โดยคลิก วันที่สั้น จาก General รายการแบบหล่นลงใต้ หน้าแรก ดูภาพหน้าจอ:

จัดเรียงเอกสารอัตโนมัติตามวันที่ 2

3. จากนั้นหมายเลขลำดับจะถูกแปลงเป็นรูปแบบวันที่และวันที่เดิมได้รับการจัดเรียงเช่นกันดูภาพหน้าจอ:

จัดเรียงเอกสารอัตโนมัติตามวันที่ 3

4. จากนี้ไปเมื่อคุณป้อนวันที่ใหม่หรือเปลี่ยนวันที่ในคอลัมน์ A วันที่ในคอลัมน์ C จะเรียงลำดับจากน้อยไปมากโดยอัตโนมัติดูภาพหน้าจอ:

จัดเรียงเอกสารอัตโนมัติตามวันที่ 4


ลูกศรสีฟ้าฟองขวา จัดเรียงวันที่อัตโนมัติเมื่อป้อนหรือเปลี่ยนวันที่ด้วยรหัส VBA

รหัส VBA ต่อไปนี้สามารถช่วยให้คุณจัดเรียงวันที่ในคอลัมน์เดิมโดยอัตโนมัติเมื่อคุณป้อนวันที่ใหม่หรือเปลี่ยนวันที่ตามที่คุณต้องการ

1. ไปที่แผ่นงานที่คุณต้องการจัดเรียงวันที่โดยอัตโนมัติเมื่อคุณป้อนหรือเปลี่ยนวันที่

2. คลิกขวาที่แท็บแผ่นงานแล้วเลือก ดูรหัส จากเมนูบริบทในป๊อปอัป Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดคัดลอกและวางรหัสต่อไปนี้ลงในช่องว่าง โมดูล หน้าต่างดูภาพหน้าจอ:

รหัส VBA: จัดเรียงอัตโนมัติเมื่อป้อนหรือเปลี่ยนแปลงวันที่:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    On Error Resume Next
    If Application.Intersect(Target, Application.Columns(1)) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    Range("A1").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
                                        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

จัดเรียงเอกสารอัตโนมัติตามวันที่ 6

หมายเหตุ: ในรหัสด้านบนวันที่ที่ป้อนจะจัดเรียงอัตโนมัติในคอลัมน์ A คุณสามารถเปลี่ยนแปลงได้ A1 และ A2 ไปยังเซลล์ของคุณเองตามที่คุณต้องการ

3. จากนี้ไปเมื่อคุณป้อนวันที่ในคอลัมน์ A วันที่จะถูกเรียงลำดับจากน้อยไปมากโดยอัตโนมัติ

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, Visio และโครงการ
  • เปิดและสร้างเอกสารหลายรายการในแท็บใหม่ของหน้าต่างเดียวกันแทนที่จะเป็นในหน้าต่างใหม่
  • เพิ่มประสิทธิภาพการทำงานของคุณ 50% และลดการคลิกเมาส์หลายร้อยครั้งให้คุณทุกวัน!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello,This is a great tool. thank you. How can i apply this to multiple columns in the same tab? Could i apply it to restart sorting by date in a new cell of the same column? Would i just repaste the VBA code into the same window?
Thank you.
This comment was minimized by the moderator on the site
Hello Noname9,How are you? To achieve your goal by using VBA code is beyond my reach. But I do know how to use formulas to do the trick.Suppose we have two columns of dates, say A2:B7. How to sort these dates into a new column? Please do as follows.
First, we need to combine the two columns of dates into one column. Copy and paste the formula =INDEX($A$2:$B$7,INT((ROWS(D$2:D2)-1)/2)+1,MOD(ROWS(D$2:D2)-1,2)+1) into cell D2. And drag the fill handle down to combine all dates. Please see screenshot 1.
Then, we will sort the combined dates. Copy and paste the formula =INDEX($D$2:$D$13,MATCH(ROWS($D$2:D2),COUNTIF($D$2:$D$13,"<="&$D$2:$D$13),0)) into F2. And drag the fill handle down to sort all dates. Please see screenshot 2.
Hope it will help. Have a nice day.Sincerely,Mandy
This comment was minimized by the moderator on the site
Hello,What if i want to do this to multiple columns or even have anew start point in the same column? Do i just do a break and recopy the VBA code in that same window?
Thank you.
This comment was minimized by the moderator on the site
That VBA code is solid gold! Thank you! :-)
This comment was minimized by the moderator on the site
With the VBA code, I have copy and pasted the above but wish for the dates in column F to be the values by which the data is sorted. I've changed the range values to F2 and F3500 (the size of the spreadsheet where row 1 is titles), but it still sorts by the dates in column A. Can somebody help me please?
This comment was minimized by the moderator on the site
Hello, Ross,
When applying the code to column F, you should change some references to your need as below code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160606
On Error Resume Next
If Application.Intersect(Target, Application.Columns(6)) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
Range("F1").Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Is there a particular formula to keep the cells following the sorted date? It would be nice to organize by date but keep the entire row of information. Any help would be much appreciated.
This comment was minimized by the moderator on the site
I mad a checkbook register and it works but I want to figure out how to make my entry’s to go into date order. Any help would be appreciated. I’m still learning excel.
This comment was minimized by the moderator on the site
In addition to the duplicate dates, is there also a way to include multiple columns of data when it sorts? I need it to include multiple columns and sort them all together with the expiration dates.
This comment was minimized by the moderator on the site
how can I do this same sorting calculation but from newest date to oldest? Currently it is Oldest to Newest. Flipping the < sign isn't enough and beyond that I don't have a strong enough understanding of what it is doing. Also I think what may be happening is excel automatically works top to bottom causing difficulties.
This comment was minimized by the moderator on the site
Hello, Bo,

To auto sort the date from newest to oldest, you just need to change the <= to >= in the above formula as follows:
=INDEX($A$2:$A$15,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$15,">="&$A$2:$A$15),0))
After inserting this formula, please remember to press Ctrl + Shift + Enter keys together to get the correct result.
Please try it.
This comment was minimized by the moderator on the site
What if there is a duplicate date in the list? And I want both numbers to show up.
This comment was minimized by the moderator on the site
Hello, Ryan,

To sort the date with duplicate ones, you should apply the following formula:

=IFERROR(INDEX($A$2:$A$11,MATCH(ROWS($A$2:A2),COUNTIF($A$2:$A$11,"<="&$A$2:$A$11),0)),IF(ROWS($A$2:A2)<ROWS($A$2:$A$11),B3,""))

Please remember to press Shift + Ctrl + Enter keys together.

Hope it can help you, thank you!
This comment was minimized by the moderator on the site
Awesome :) Working fine
This comment was minimized by the moderator on the site
U forgot to mention the formula is array and you need to ctrl+Shift+ enter. Luckily you had a screenshot or your page would be a waste of cyberspace
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations