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

วิธีล็อคหรือตรึงแท็บแผ่นงานใน Excel

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

ล็อกหรือตรึงแท็บแผ่นงานเฉพาะด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา ล็อกหรือตรึงแท็บแผ่นงานเฉพาะด้วยรหัส VBA

ใน Excel เราสามารถใช้รหัส VBA ต่อไปนี้เพื่อสร้างแผ่นงานเฉพาะก่อนแท็บแผ่นงานที่คลิกปัจจุบันของคุณเสมอเพื่อให้คุณสามารถเห็นแผ่นงานนี้ได้เสมอเมื่อคุณเลื่อนไปตามแท็บแผ่นงานอื่น ๆ กรุณาดำเนินการดังนี้:

1. กด ALT + F11 และจะเปิดไฟล์ หน้าต่าง Microsoft Visual Basic for Applications.

2. จากนั้นเลือก สมุดงานนี้ จากด้านซ้าย นักสำรวจโครงการ บานหน้าต่างให้ดับเบิลคลิกเพื่อเปิดไฟล์ โมดูลจากนั้นคัดลอกและวางโค้ด VBA ต่อไปนี้ลงในโมดูลเปล่า:

รหัส VBA: ตรึงหรือล็อกแท็บแผ่นงานเฉพาะ

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Update by Extendoffice
Application.EnableEvents = False
Application.ScreenUpdating = False
If Application.ActiveSheet.Index <> Application.Sheets("Main-sheet").Index Then
    Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index)
    Application.Sheets("Main-sheet").Activate
    Sh.Activate
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

doc-freeze-sheet-tab-1

3. จากนั้นบันทึกและปิดรหัสนี้ตอนนี้เมื่อคุณคลิกแท็บแผ่นงานใด ๆ ของคุณแผ่นงานเฉพาะนี้จะอยู่ที่ด้านหน้าของแท็บแผ่นงานที่คุณคลิกเสมอดูภาพหน้าจอ:

doc-freeze-sheet-tab-2
-1
doc-freeze-sheet-tab-3

หมายเหตุ: ในรหัสด้านบนแผ่นงานหลักคือชื่อแผ่นงานที่คุณต้องการตรึงคุณสามารถเปลี่ยนได้ตามต้องการ


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

วิธีการตรึงบานหน้าต่างใน Excel 2010

จะใช้บานหน้าต่างตรึง / ยกเลิกการตรึงกับแผ่นงานหลายแผ่นพร้อมกันได้อย่างไร

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

🤖 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 (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
chăng đc gi cả
This comment was minimized by the moderator on the site
As Thuyen pointed out 2 years ago, you can't copy data between sheets while this code is active. Furthermore, the code is needlessly complicated. The sheet that you activate is passed to the procedure as the parameter "Sh". This makes the frequent calls to "ActiveSheet" unnecessary, and could cause problems for someone who's trying to modify the code but isn't very experienced.

Here's my versions that corrects those issues, and even shows how to add a 2nd "Main" sheet (similar to what Dzingai posted):
-----------------------------------------------------------------

'These 2 lines aren't necessary if you use the sheets' codenames, which I recommend.
Set shtMain1 = Worksheets("Main-Sheet-1")
Set shtMain2 = Worksheets("Main-Sheet-2")

If Application.CutCopyMode = False Then
If Sh.Index <> shtMain1.Index And Sh.Index <> shtMain2.Index Then
shtMain1.Move before:=Sh
shtMain2.Move before:=Sh
Sh.Activate
End If
End If
This comment was minimized by the moderator on the site
This code worked well. Only problem is...if we close the file & open it again it goes off.
This comment was minimized by the moderator on the site
[quote]This code worked well. Only problem is...if we close the file & open it again it goes off.By Sangs[/quote] Try saving document as Macro-Enabled Workbook. I think it should work well that way.
This comment was minimized by the moderator on the site
Is it possible to create one with multiple arguments? Like instead of just moving the one main sheet to the front of where you are working, is it possible to move three tabs in front of what you are working on?
This comment was minimized by the moderator on the site
Yes, it is possible, you just have to add more arguments to the if clause using the "AND" like this IF Application.ActiveSheet.Index Application.Sheets("Main-sheet").Index AND Application.ActiveSheet.Index Application.Sheets("Other-Main-sheet").Index and so on... Then Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.Sheets("Other-Main-sheet").Index) Application.Sheets("Main-sheet").Activate Application.Sheets("Other-Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index) Application.Sheets("Other-Main-sheet").Activate Sh.Activate This will place the Main-Sheet, then the Other-Main-Sheet in front of your active sheet.
This comment was minimized by the moderator on the site
is this vba my excel sheet not freezeplease give me solution
This comment was minimized by the moderator on the site
Could not get your code to work, but this one did :) Private Sub Workbook_SheetActivate(ByVal Sh As Object) Dim sc As Long ' count of sheets Dim NewPos As Long ' index of serlected sheet Application.EnableEvents = False Application.ScreenUpdating = False If ActiveSheet.Index 1 Then sc = Sheets.Count NewPos = ActiveSheet.Index For i = 2 To NewPos - 1 Sheets(2).Move After:=Sheets(sc) Next i Sheets(1).Activate Sheets(2).Activate End If Application.ScreenUpdating = True Application.EnableEvents = True End Sub
This comment was minimized by the moderator on the site
When I use VBA, I cannot copy data from Main-Sheet to another sheet Please help me fix this bug
This comment was minimized by the moderator on the site
hahaha. so true! did you find a fix for this?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations