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

วิธีล้างเนื้อหาเซลล์ที่ระบุเมื่อเปิดและออกในสมุดงาน Excel

บทความนี้พูดถึงการล้างเนื้อหาเซลล์ที่ระบุเมื่อเปิดหรือปิดสมุดงาน Excel

ล้างเนื้อหาเซลล์ที่ระบุบนเวิร์กบุ๊กเปิดและออก


ล้างเนื้อหาเซลล์ที่ระบุบนเวิร์กบุ๊กเปิดและออก

โปรดทำดังนี้เพื่อล้างเนื้อหาของเซลล์ที่ระบุบนสมุดงานเปิดและออก

ประการแรกคุณต้องบันทึกเวิร์กบุ๊กซึ่งคุณต้องล้างเนื้อหาของเซลล์ที่ระบุเมื่อเปิดหรือออกเป็นเวิร์กบุ๊กที่เปิดใช้งานแมโคร Excel

1. กรุณาคลิก เนื้อไม่มีมัน > บันทึกเป็น > หมวดหมู่สินค้า. ดูภาพหน้าจอ:

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

3. ในการโผล่ขึ้นมา Microsoft Excel โปรดคลิกที่ไฟล์ OK ปุ่มด้านล่างภาพหน้าจอที่แสดง

4. เปิดสมุดงานที่เปิดใช้งานมาโครที่คุณบันทึกไว้ตอนนี้กดปุ่ม อื่น ๆ + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

5 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน ดับเบิลคลิก สมุดงานนี้ ในบานหน้าต่างด้านซ้ายจากนั้นคัดลอกโค้ด VBA ด้านล่างลงในหน้าต่างรหัส

รหัส VBA 1: ล้างเนื้อหาเซลล์ที่ระบุบนสมุดงานที่เปิดอยู่

Private Sub Workbook_Open()
'Updated by Extendoffice 20190712
    Application.EnableEvents = False
        Worksheets("test").Range("A1:A11").Value = ""
    Application.EnableEvents = True
End Sub

รหัส VBA 2: ล้างเนื้อหาเซลล์ที่ระบุเมื่อออกจากสมุดงาน

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Updated by Extendoffice 20190712
    Worksheets("test").Range("A1:A11").Value = ""
End Sub

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

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

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


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

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

🤖 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 (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank You Crystal! It works.

G
This comment was minimized by the moderator on the site
Dear Friends I tried the suggested code with no effect on open>

Private Sub Workbook_Open()


Application.EnableEvents = False

Worksheets("Clienti").Range("A9:K900").Value = ""

Application.EnableEvents = True

End Sub


The macro does work from within the workbook but not when the workbook opens.

Any help would be greatly appreciated!
This comment was minimized by the moderator on the site
Hi TUDOSE GELU,
The code works well in my case.
Don't forget to put the code in the ThisWorkbook (Code) window, and save the workbook as an Excel Macro-Enabled Workbook.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/2022-oct/oct-2.png
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/2022-oct/oct-1.png
This comment was minimized by the moderator on the site
Can someone help me how to blankout cells of sheet (only in a row and not entire Sheet). Below code removes contents in all rows of the sheet. But I want contents to be cleared only in row9



Private Sub Workbook_Open()

'Updated by Extendoffice 20190712

Application.EnableEvents = False

Worksheets("test").Range("A1:A11").Value = ""

Application.EnableEvents = True

End Sub
This comment was minimized by the moderator on the site
Hi,
The above VBA only clear the cell value of range A1:A11. If you want to clear only the values in row 9, you can replace A1:A11 with 9:9. See the below code.

Private Sub Workbook_Open()

'Updated by Extendoffice 20200522

Application.EnableEvents = False

Worksheets("test").Range("9:9").Value = ""

Application.EnableEvents = True

End Sub
This comment was minimized by the moderator on the site
Can someone help me how to blankout cells of sheet (only in a row and not entire Sheet). Below code removes contents in all rows of the sheet. But I want contents to be cleared only in row9

Private Sub Workbook_Open()

'Updated by Extendoffice 20190712

Application.EnableEvents = False

Worksheets("test").Range("A1:A11").Value = ""

Application.EnableEvents = True

End Sub
This comment was minimized by the moderator on the site
Hello, for the range how would I enter the code if I want to select multiple range or cells?
This comment was minimized by the moderator on the site
Dear sir/madam, my sheet is protected and only specified cell (for data clearing) is not protected but when i enter the value in the specified & then re-open the excel file then value is cleared by VBA code but the specified cell is protected, i have to un-protect cell by un-protecting the sheet edit the editable range again & again so please fix.
Thanks in advance
This comment was minimized by the moderator on the site
Hi Sanjay Sharma,
Sorry for the inconvinience. Please apply the below VBA codes and remember to replace the sheet name and the range to your needs. Thank you for your comment.

VBA code 1:
Private Sub Workbook_Open()
Application.EnableEvents = False
Worksheets("Sheet1").Range("A1:A11").Value = ""
Application.EnableEvents = True
End Sub

VBA code 2:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Range("A1:A11").Value = ""
End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations