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

วิธีเปลี่ยนสีของเซลล์เมื่อเซลล์ถูกคลิกหรือเลือกใน Excel

บทความนี้จะแสดงวิธีการเปลี่ยนสีของเซลล์ในขณะที่คลิกที่เซลล์และเปลี่ยนสีที่ไฮไลต์ในขณะที่เลือกช่วงของเซลล์ใน Excel

เปลี่ยนสีของเซลล์เมื่อคลิกเซลล์ด้วยรหัส VBA
เปลี่ยนสีที่ไฮไลต์เมื่อเซลล์ถูกเลือกด้วยรหัส VBA
เน้นทั้งแถวและคอลัมน์ของเซลล์ที่ใช้งานด้วย Kutools for Excel


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

ที่นี่คุณสามารถเปลี่ยนสีพื้นหลังของเซลล์เมื่อดับเบิลคลิกหรือคลิกขวาด้วยรหัส VBA ต่อไปนี้

1. ในแผ่นงานคุณจะเปลี่ยนสีของเซลล์เมื่อคลิกคลิกขวาที่แท็บแผ่นงานแล้วคลิก ดูรหัส จากเมนูคลิกขวา

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดคัดลอกและวางโค้ด VBA ด้านล่างลงในไฟล์ รหัส หน้าต่าง

VBA: เปลี่ยนสีของเซลล์เมื่อคลิกที่มัน

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbRed
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbGreen
End Sub

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

จากนั้นเมื่อคุณคลิกสองครั้งที่เซลล์เซลล์นั้นจะเป็นสีแดง และเมื่อคุณคลิกขวาที่เซลล์เซลล์นั้นจะเป็นสีเขียว ดูภาพหน้าจอ:


คลิกเพียงครั้งเดียวเพื่อเน้นแถวและคอลัมน์ของเซลล์ที่เลือกใน Excel:

Kutools สำหรับ Excel's การอ่านเค้าโครง ยูทิลิตี้ช่วยให้คุณเน้นแถวและคอลัมน์ของเซลล์ที่เลือกใน Excel ได้อย่างรวดเร็วดังตัวอย่างด้านล่างที่แสดง
ดาวน์โหลดและทดลองใช้ทันที! (เส้นทางฟรี 30 วัน)


เปลี่ยนสีที่ไฮไลต์เมื่อเซลล์ถูกเลือกด้วยรหัส VBA

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

1. คลิกขวาที่แท็บแผ่นงานที่คุณต้องการเปลี่ยนสีที่ไฮไลต์ของช่วงที่เลือกแล้วคลิก ดูรหัส จากเมนูคลิกขวา

2 ใน Microsoft Visual Basic สำหรับแอปพลิเคชัน โปรดคัดลอกและวางโค้ด VBA ด้านล่างลงในไฟล์ รหัส หน้าต่าง

รหัส VBA: เปลี่ยนสีที่ไฮไลต์ของช่วงที่เลือก

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Target
        .Worksheet.Cells.FormatConditions.Delete
        .FormatConditions.Add xlExpression, , "TRUE"
        .FormatConditions(1).Interior.Color = vbYellow
    End With
End Sub

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

จากนี้ไปสีที่ไฮไลต์ของช่วงหรือเซลล์ที่เลือกจะเปลี่ยนเป็นสีเหลือง เมื่อคุณคลิกเซลล์อื่นหรือช่วงของเซลล์อื่นเซลล์จะมีสีโดยอัตโนมัติ


เน้นทั้งแถวและคอลัมน์ของเซลล์ที่ใช้งานด้วย Kutools for Excel

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

ก่อนที่จะใช้ Kutools สำหรับ Excelโปรด ดาวน์โหลดและติดตั้งในตอนแรก.

1 คลิก Kutools > การอ่านเค้าโครง. ดูภาพหน้าจอ:

จากนั้นเปิดใช้งานเค้าโครงการอ่านคุณจะเห็นแถวและคอลัมน์ของเซลล์ที่ใช้งานอยู่จะถูกไฮไลต์ทันที

หมายเหตุ: คุณสามารถเปลี่ยนการตั้งค่ารูปแบบการอ่านได้ตามความต้องการของคุณตามภาพด้านล่างที่แสดง

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


เน้นทั้งแถวและคอลัมน์ของเซลล์ที่ใช้งานด้วย Kutools for Excel

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

🤖 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 (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, i built a dashboard with 37 worksheets, everyone with a table. All of them are lock panels because are to large and i need to know the number and name of the student who am i entering data for. Despite that, i have to keep my finger on the left side of the screen to identify the names and numbers to which the entered data refer.  So, i need to identify the first two cells of the row, in the columns "I" and "J".
The code that i took from the internet and couldn't change for the two cells of columns "I" and "J" was:

Dim lTarget As Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Row >= 16 Then

If Not lTarget Is Nothing Then

lTarget.EntireRow.Interior.ColorIndex = 0
End If

Target.EntireRow.Interior.Color = 9359529

Set lTarget = Target
End If
End Sub

All tables begin in diferent rows. This example start in 16 row but i put the code in all the pages and adapt to the needs of the specific row number. 
I've already tried to change the code from EntireRow to Range ("I16:J43") but the cells were in the range became all painted with the code color.
Already try a diferent way through the "conditional formatting" with the formula =E($I16<>"";LIN()=CÉL("lin")) in the range $I16:$J43, and in the developer "worksheet", with "Application.Calculate" and it works. I change in the 37 worksheets but i was copying and data from the previous file to this new one and I noticed that the options to paste "values", etc, disappear from my dashboard. The code must be executing something that, like clicking on the cell, no longer lets it paste. A single option was to paste with CTRL+V.
If someone can help me with the code, i'll delete the VBA "Application.Calculate" to to get back to the available collage options.
Thak you for your help.

Luís Lopes
This comment was minimized by the moderator on the site
Hello, the code used to work for a while, but now it doesn't anymore. What can there be wrong?
This comment was minimized by the moderator on the site
Hi Rens Borburgh,There are two codes provided in the post, which one did you use? Did you get any error prompt?
This comment was minimized by the moderator on the site
I have tried them both at the same time. After copying it to a usb stick it didn't work anymore.
This comment was minimized by the moderator on the site
Hi Rens Borburgh,I don't quite understand what you mean. The codes should be used in the sheet code window and not in the Module window. Or can you provide a screenshot of your code window?
This comment was minimized by the moderator on the site
Hi, I am trying to use the double click option to change a cell to green but i also want that cell to go back to no fill or white if i double click it whilst it is green. Is this possible? 
This comment was minimized by the moderator on the site
alguien que me ayude solo quiero que al hacerle click a una celda se ponga de un color y que se mantenga ese color y si le vuelvo hacer click regrese el color original que tenia
This comment was minimized by the moderator on the site
How to highlight the cell(with data) to automatically highlight the other cells (data which is related another data in a previous cell) with click of the cell.Can i do it. Is there a way to do it.
This comment was minimized by the moderator on the site
The code works as long as I do not protect the worksheet. Once I protect the worksheet, because I have conditional formatting on locked cells, the code will not work. How can I change this so that it works on locked worksheet where the user can select unlocked cells?
This comment was minimized by the moderator on the site
Hi,
is it possible to have a code for "change cell color when clicking on it" in the way that it will not change already formated cells with another color, please?
After applying your code all my formating (colours) is away. Thank you. Veronika
This comment was minimized by the moderator on the site
Thank you. Great Job
This comment was minimized by the moderator on the site
hi
the is working grate but i want that the color should only be when the cell is selected and when i select something else, the first cell i selcted should not be colored
can you help me pls with this thanks
This comment was minimized by the moderator on the site
I had that exact same question! I hope someone will answer you! The reason I am looking for this is I have a spreadsheet I use daily and put in lots of information into single cells. It gets hard to see the values (visually, it runs into info in other cells), and would be a great feature if I could change the color of the cell being edited - only while it is being edited. The simplest solution I can think of is that the cell value would be set back to what it was prior to being clicked on - but I don't know how to do that.
This comment was minimized by the moderator on the site
Hi, I am trying to figure out how to change the color of a cell, based on a selection from a dropdown list. For example, HIGH=red, MEDIUM=yellow, LOW=green.

Any tips you can provide are greatly appreciated. Thank You
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