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

วิธีการจัดรูปแบบเซลล์ในขณะที่อ้างอิงเซลล์แผ่นงานอื่น ๆ

โดยทั่วไปเซลล์จะเก็บเฉพาะค่าของเซลล์ในขณะที่อ้างอิงเซลล์อื่น แต่ในบทความนี้ฉันแนะนำรหัส VBA เพื่อเก็บค่าของเซลล์และการจัดรูปแบบในขณะที่อ้างอิงเซลล์อื่นและค่าของเซลล์และการจัดรูปแบบจะเปลี่ยนไปเมื่อเซลล์อ้างอิงเปลี่ยนแปลงดังต่อไปนี้ แสดงภาพหน้าจอ
doc จัดรูปแบบในขณะที่อ้างถึง 1

จัดรูปแบบเซลล์ในขณะที่อ้างอิงเซลล์อื่นด้วย VBA


จัดรูปแบบเซลล์ในขณะที่อ้างอิงเซลล์อื่นด้วย VBA

ในการจัดการงานนี้คุณต้องเรียกใช้โค้ดด้านล่าง

1. เปิดใช้งานสมุดงานที่คุณใช้กด Alt + F11 กุญแจสำคัญในการเปิดใช้งาน Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างและดับเบิลคลิกที่ชื่อแผ่นงานซึ่งคุณจะวางเซลล์อ้างอิงไว้ โครงการ -VBAProject บานหน้าต่างเพื่อแสดงสคริปต์เปล่า ในกรณีนี้ฉันต้องการอ้างถึงเซลล์ A1 ใน Sheet1. ดูภาพหน้าจอ:
doc จัดรูปแบบในขณะที่อ้างถึง 2

2. วางโค้ดด้านล่างลงในสคริปต์และในรหัส VBA ระบุการอ้างอิงเซลล์ตามที่คุณต้องการ

VBA: รักษาการจัดรูปแบบและค่าในขณะที่อ้างอิงเซลล์อื่น

Private Sub Worksheet_Activate()
'UpdatebyExtendoffice20101024
    Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Or Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    If Not Intersect(Target, Range("A1")) Is Nothing Then              'Range("A1") the reference cell
        Target.Copy
        ActiveWorkbook.Sheets("Sheet2").Range("B1").PasteSpecial xlPasteAllUsingSourceTheme
                    'Range("B1")the cell linked to reference cell,ActiveWorkbook.Sheets("Sheet2")the sheet which contains linked cell
        Application.CutCopyMode = False
        Target.Select
    End If
    Application.EnableEvents = True
End Sub

หมายเหตุ: A1 คือเซลล์อ้างอิง B1 in ฮิตแผ่น คือเซลล์ที่คุณต้องการเชื่อมโยงไปยังเซลล์อ้างอิงและเก็บค่าและจัดรูปแบบด้วย A1 ใน Shee1

จากนั้นเมื่อคุณเปลี่ยนค่าหรือการจัดรูปแบบในเซลล์ A1 ใน Sheet1 เซลล์ B1 ใน Sheet2 จะเปลี่ยนไปในขณะที่คลิกที่เซลล์อ้างอิงสองครั้ง


นับตามสี

ในบางกรณีคุณอาจมีช่วงของ calues ​​ที่มีหลายสีและสิ่งที่คุณต้องการคือการนับ / รวมค่าตามสีเดียวกันคุณจะคำนวณอย่างรวดเร็วได้อย่างไร?
กับ Kutools สำหรับ Excel's นับตามสีคุณสามารถทำการคำนวณหลายสีได้อย่างรวดเร็วและยังสามารถสร้างรายงานผลการคำนวณได้อีกด้วย
เอกสารนับตามสี

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

🤖 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 (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, I would like to keep the format of my reference cell. However, even with your VBA it doesn't work. Can you help me please?
I would like my B2 cell of my sheet 1 to be my reference cell for my C2 cells of sheets 2,3,4,5,6,7.
My document is a list of people, therefore I will have several cells of references not the continuation.
Thanks in advance
This comment was minimized by the moderator on the site
No tienes uno que sea dentro del mismo archivo
This comment was minimized by the moderator on the site
Thanks for sharing this. I have a range of cells in WorksheetA, Sheet1, Range G3:G3000 that I want to reference in WorksheetB, Sheet1, Range G3:G3000. I need WorksheetB, Sheet1, Range G3:G3000 to display both the value and the format of the referenced cells in WorksheetA, Sheet1, G3:G3000. Is there a VBA script that will allow for this?
This comment was minimized by the moderator on the site
Thanks for sharing this. Is there a VBA script that allows for referencing a range of cells in one workbook and then displaying the value and format of the referenced cells in a different workbook?
This comment was minimized by the moderator on the site
Thank you so much for the script. Can you tell me if there is a way for the linked cell to update without having to double click on the reference cell? Thank you!
This comment was minimized by the moderator on the site
hello, I believe this may be just what I am looking for. I need the referenced text to have the same colors and features from the referenced page. The only thing different about mine is that I am pulling from a larger range. I have never used VBA before so I wanted to confirm before I did changes. I am pulling from a document (sheet 2) onto (sheet 1) document. I have used IF formulas to do this, so it returns a value from 3 different columns and they are not in a row. The columns are F,H,J. Could you please help me figure out how I can make this work?
This comment was minimized by the moderator on the site
I am dealing with similar issue. I have a formula in column C, which takes value from the same row, column A. (But only IF B3 is not x AND A3 is not empty):

=IF(B3="x";"y";IF(A3="";"z";A3))

Cells of column A look like this: OK 2019_12_03
But "OK" is in bold format. I would like to keep this format.
I want this for hundreds of cells, so clicking or writing a script for each one of them is undesirable. Any ideas if such feature exists? I'd appreciate some kind of "WITHFORMAT()" function that I could put in the formula, so the following formula would keep the original format:

=IF(B3="x";"y";IF(A3="";"z";WITHFORMAT(A3)))
This comment was minimized by the moderator on the site
Sorry, your problem is a bit complex, I do not understand clearly.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations