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

วิธีการเปลี่ยนค่าเซลล์โดยคลิกที่เซลล์?

เป็นไปได้ไหมที่เราจะเปลี่ยนค่าเซลล์โดยคลิกที่เซลล์ใน Excel ตัวอย่างเช่นเมื่อคุณคลิกเซลล์ A1 ที่ต้องการในครั้งแรกจะแสดงข้อความ“ Excel” หากคุณคลิก A1 อีกครั้งข้อความ“ Word” จะปรากฏขึ้นและข้อความ“ Outlook” จะปรากฏขึ้นเมื่อคุณคลิกที่นี่ เซลล์ในครั้งที่สาม ในกรณีนี้ค่าในเซลล์ A1 จะเกิดซ้ำจาก "Excel" เป็น "Word" เป็น "Outlook" เป็น "Excel" ……ดังภาพหน้าจอต่อไปนี้:

doc เปลี่ยนค่าโดยคลิกที่ 1

เปลี่ยนค่าเซลล์โดยคลิกที่เซลล์ด้วยรหัส VBA


ลูกศรสีฟ้าฟองขวา เปลี่ยนค่าเซลล์โดยคลิกที่เซลล์ด้วยรหัส VBA

เพื่อให้งานนี้เสร็จสิ้นใน Excel รหัส VBA ต่อไปนี้อาจช่วยคุณได้โปรดทำดังนี้:

1. คลิกขวาที่แท็บแผ่นงานที่คุณต้องการเปลี่ยนค่าของเซลล์โดยคลิกที่แล้วเลือก ดูรหัส จากเมนูบริบทและในเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่างคัดลอกและวางรหัสต่อไปนี้ลงในโมดูลเปล่า:

รหัส VBA: เปลี่ยนค่าเซลล์โดยคลิกที่เซลล์:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'Updateby Extendoffice
  Application.EnableEvents = False
  With Target
  If .Address = Range("A1").Address Then
    Select Case .Value
      Case "Excel"
        .Value = "Word"
      Case "Word"
        .Value = "Outlook"
      Case "Outlook"
        .Value = "Excel"
      Case Else
        .Value = "Word"
    End Select
  End If
  End With
  Range("A2").Select
  Application.EnableEvents = True
End Sub

doc เปลี่ยนค่าโดยคลิกที่ 2

หมายเหตุ: ในโค้ดด้านบน A1 คือเซลล์ที่คุณต้องการเปลี่ยนค่าโดยคลิก "Excel","คำ","Outlook” คือค่าของเซลล์ที่คุณต้องการให้แสดงเป็นประจำคุณสามารถเปลี่ยนค่าเหล่านั้นได้ตามต้องการ

2. หลังจากวางรหัสแล้วให้บันทึกรหัสและปิดหน้าต่าง ตอนนี้เมื่อคุณคลิกเซลล์ A1 ในครั้งแรกข้อความ“ Excel” จะปรากฏขึ้นพร้อมกันคลิกอีกครั้งข้อความ“ Word” จะปรากฏขึ้นข้อความ“ Outlook” จะปรากฏขึ้นหากคุณคลิกในครั้งที่สาม ดูภาพหน้าจอ:

doc เปลี่ยนค่าโดยคลิกที่ 1


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

วิธีกรองข้อมูลเพียงแค่คลิกเนื้อหาเซลล์ใน Excel

วิธีจัดเรียงข้อมูลคอลัมน์โดยคลิกที่ส่วนหัวใน 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 (7)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This is great information, thanks for everyone's input! Is there away to apply this same type of approach with a lookup or index\match value?

For example, if I click on a value in A1, can the VBA be configured to index that value in another worksheet column, and display a matched value in B1? Thank you again!
This comment was minimized by the moderator on the site
I am trying to apply this to an entire column of individual cells, not just one cell. Is this possible? When I change the range from "A1" to "A1:A100" nothing happens when I click the cells in that range.
This comment was minimized by the moderator on the site
This is the final code that worked for me.  I use it to check a cell when an item is completed.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.EnableEvents = False
    With Target
      Dim KeyCells As Range
      Set KeyCells = Range("D6:D8000")
      If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        Select Case .Value
          Case "ü"
            .Value = ""
          Case ""
            .Value = "ü"
        End Select
      End If
    End With
  Application.EnableEvents = True
End Sub
This comment was minimized by the moderator on the site
You can do that by declaring the range you want to have as KeyCells and than put that into the Application.Intersection Method. This will let you change the Value of your choice from all the cells. Worked for me but i am bad at explaining ^^


Application.EnableEvents = False
With Target


Dim KeyCells as Range

Set KeyCells = Range("A1:A100")

If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then

Select Case .Value

...
This comment was minimized by the moderator on the site
You can do that by declaring the range you want to have as KeyCells and than put that into the Application.Intersection Method. This will let you change the Value of your choice from all the cells. Worked for me but i am bad at explaining ^^

Dim KeyCells as Range

Set KeyCells = Range("A1:A100")

If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then

Select Case .Value

...
This comment was minimized by the moderator on the site
I did it but i will not tell anyone MUWAHAHAHAHAHAHAHAHAHA
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations