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

จะแสดงปฏิทินเมื่อคลิกเซลล์ใดเซลล์หนึ่งใน Excel ได้อย่างไร?

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


เปิดปฏิทินเมื่อคลิกเซลล์ที่ต้องการด้วยรหัส VBA

โปรดแก้ไขปัญหานี้ตามขั้นตอนต่อไปนี้

หมายเหตุ: วิธีนี้ใช้ได้กับ Microsoft Excel 32 บิตเท่านั้น

ขั้นตอนที่ 1: สร้าง UserForm ด้วยปฏิทิน

โปรดสร้าง UserForm ซึ่งมีปฏิทินที่คุณจะปรากฏขึ้นโดยคลิกที่เซลล์

1 กด อื่น ๆ + F11 พร้อมกันเพื่อเปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคลิก สิ่งที่ใส่เข้าไป > แบบฟอร์มผู้ใช้.

3. จากนั้นก แบบฟอร์มผู้ใช้ และ กล่องเครื่องมือ หน้าต่างจะปรากฏขึ้นใน กล่องเครื่องมือคลิกปุ่มควบคุมใดปุ่มหนึ่งแล้วคลิกขวาจากนั้นเลือก การควบคุมเพิ่มเติม จากเมนูคลิกขวา ดูภาพหน้าจอ:

4 ใน การควบคุมเพิ่มเติม กล่องโต้ตอบเลื่อนลงเพื่อตรวจสอบไฟล์ การควบคุม Microsoft MonthView ตัวเลือกใน การควบคุมที่มีอยู่ จากนั้นคลิกที่ไฟล์ OK ปุ่ม

5. จากนั้นคุณจะเห็นไฟล์ มุมมองรายเดือน เพิ่มปุ่มในไฟล์ กล่องเครื่องมือ หน้าต่าง. โปรดคลิกปุ่ม MonthView นี้จากนั้นคลิกที่หน้าต่าง UserForm1 เพื่อสร้างปฏิทินใน Userform

หมายเหตุ: คุณสามารถปรับขนาดของหน้าต่าง UserForm ให้เหมาะกับปฏิทินที่แทรกได้โดยลากเส้นขอบของ UserForm

6. ดับเบิลคลิกที่ปฏิทินที่แทรกใน UserForm1 และในไฟล์ รหัส โปรดแทนที่รหัสเดิมด้วยสคริปต์ VBA ต่อไปนี้

VBA code: create a user form with calendar

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
 On Error Resume Next
   Dim xRg As Object
   For Each xRg In Selection.Cells
      xRg.Value = DateClicked
   Next xRg 
   Unload Me
End Sub

หมายเหตุ: รหัสนี้สามารถช่วยในการแทรกวันที่ลงในเซลล์ที่เลือกหลังจากเลือกวันที่จากปฏิทิน

ขั้นตอนที่ 2: เปิดใช้งานปฏิทินเมื่อคลิกที่เซลล์

ตอนนี้คุณต้องระบุเซลล์ที่จะแสดงปฏิทินเมื่อคลิก กรุณาดำเนินการดังนี้

7. ดับเบิลคลิกชื่อแผ่นงานที่มีเซลล์ที่คุณจะคลิกเพื่อแสดงปฏิทินทางด้านซ้าย โครงการ บานหน้าต่างจากนั้นคัดลอกและวางโค้ด VBA ด้านล่างลงในหน้าต่างรหัส ดูภาพหน้าจอ:

VBA code: Click cell to pop up calendar

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If (Target.Count = 1) Then
    If Not Intersect(Target, Range("A2:A10")) Is Nothing Then UserForm1.Show
    End If
End Sub

หมายเหตุ: ในรหัส A2: A10 คือเซลล์ที่คุณจะคลิกเพื่อแสดงปฏิทิน โปรดเปลี่ยนช่วงเซลล์ตามที่คุณต้องการ

8 กด อื่น ๆ + Q พร้อมกันเพื่อปิดไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

จากนี้ไปเมื่อคลิกที่เซลล์ใด ๆ ภายในช่วงที่ระบุในแผ่นงานปัจจุบันปฏิทินจะปรากฏขึ้นตามภาพด้านล่างที่แสดง และวันที่จะถูกแทรกโดยอัตโนมัติในเซลล์ที่เลือกหลังจากเลือกวันที่จากปฏิทิน


เปิดปฏิทินเมื่อคลิกเซลล์ที่ต้องการด้วยรหัส VBA

ส่วนนี้จะแนะนำไฟล์ เลือกวันที่ ประโยชน์ของ Kutools สำหรับ Excel. หลังจากเปิดใช้งานคุณสมบัตินี้แล้วให้คลิกเซลล์วันที่จะแสดงปฏิทินขึ้นมาคุณสามารถแทนที่วันที่ที่มีอยู่ด้วยวันที่ใหม่ได้อย่างง่ายดาย โปรดทำตามขั้นตอนด้านล่างเพื่อใช้คุณสมบัตินี้

1 คลิก Kutools > คอนเทนต์ > เปิดใช้งานตัวเลือกวันที่.

2. หลังจากเปิดใช้งานคุณสมบัตินี้ให้คลิกที่เซลล์วันที่จากนั้นไอคอนปฏิทินจะปรากฏขึ้นที่เซลล์นั้น

3. คลิกไอคอนปฏิทินเพื่อเปิดไฟล์ เลือกวันที่ กล่องโต้ตอบจากนั้นคลิกวันที่ใหม่เพื่อแทนที่วันที่ในเซลล์ที่เลือก

หมายเหตุ:

  • ปุ่มเลิกทำ: คลิกปุ่มนี้เพื่อเลิกทำการเปลี่ยนวันที่
  • ปุ่มปิด: คลิกปุ่มนี้เพื่อปิดกล่องโต้ตอบตัวเลือกวันที่
  • ฟีเจอร์นี้ใช้ได้กับเซลล์ที่มีวันที่เท่านั้น

  หากคุณต้องการทดลองใช้ยูทิลิตีนี้ฟรี (30 วัน) กรุณาคลิกเพื่อดาวน์โหลดแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น


บทความที่เกี่ยวข้อง:

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

🤖 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 (18)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I am not seeing the Microsoft MonthView Control in the listing, but it may be as Pete (#32847) mentioned that this will not work in Office 365 or 64-bit Microsoft Office.
This comment was minimized by the moderator on the site
Hi Teagan Caudle,
I searched and tried the methods suggested in google, but ultimately could not register the MonthView control in Microsoft 365.
Sorry for the inconvenience. Maybe you can check this out.
https://social.technet.microsoft.com/Forums/Azure/en-US/db3b4dff-aad7-4d88-87cc-8f3f117be550/microsoft-windows-common-controls-60-for-office-2016
This comment was minimized by the moderator on the site
There is no Microsoft MonthView Control listed (Office 365), and the directions here doesn't explain how one would get that control, so this is pretty much useless unless you're using an older version of Excel.
This comment was minimized by the moderator on the site
The calendar will show up but when I click on the date, the cell doesn't populate
This comment was minimized by the moderator on the site
Hi,
The code works well in my case. Which Excel version are you using?
This comment was minimized by the moderator on the site
Thank you so much! These directions were super useful :)
This comment was minimized by the moderator on the site
Hi, Is it possible to put the date picker pop-up for multiple column, as in my sheet I have "start date", "end date" and "agreement date". if yes then how?
This comment was minimized by the moderator on the site
Hi jeet,
Follow the steps and replace the range "A2:A10" in the second VBA code with your column range (such as C2:E2).
This comment was minimized by the moderator on the site
Salve il codice funziona benissimo, ma se volessi farlo funzionare anche su un altro foglio
This comment was minimized by the moderator on the site
if i try to select a row, the pop up will activate and the date appears in each cell in that row


how can i avoid this
This comment was minimized by the moderator on the site
Hi Sam,
The code has been updated in the article with the problem solving. Please have a try and thank you for your comment.
This comment was minimized by the moderator on the site
tarihi seçebiliyorum ama a1:a10 hücrelerine seçtiğim tarih eklenmiyor. teşekkür ederim
This comment was minimized by the moderator on the site
Hello everyone,

Can anyone tell me how to popup a calendar in a range of cells, but starting only from the cell right bellow a table header and down bellow in an excel column.


Thank you in advance.
This comment was minimized by the moderator on the site
Use i.e: Range("B6:C30")
This comment was minimized by the moderator on the site
Good Day,
Sorry I didn't got your question. Would be nice if you could provide screenshot of what you are trying to do.
This comment was minimized by the moderator on the site
Use i.e: Range("B6:C30")
This comment was minimized by the moderator on the site
i used these VBA codes and everthing's fine so far. The range is A2:A10 and calendar pops up when you select a cell into it. But if you mark row from 2 to 10 again the calendar pops again. It's the same with column "A" if you mark it, again the calendar pops. How should i proceed, in order to get the calendar only in the range i've defined?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations