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

 วิธีสร้างรายการแบบหล่นลง แต่แสดงค่าต่างกันใน Excel

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

doc dropdown ค่าต่างๆ 1

สร้างรายการแบบหล่นลง แต่แสดงค่าที่แตกต่างกันในเซลล์รายการแบบหล่นลง


สร้างรายการแบบหล่นลง แต่แสดงค่าที่แตกต่างกันในเซลล์รายการแบบหล่นลง

เพื่อให้งานนี้เสร็จสิ้นโปรดทำตามขั้นตอนต่อไปนี้:

1. สร้างชื่อช่วงสำหรับค่าเซลล์ที่คุณต้องการใช้ในรายการแบบเลื่อนลงในตัวอย่างนี้ฉันจะป้อนชื่อแบบเลื่อนลงใน ชื่อ: กล่องจากนั้นกด เข้าสู่ สำคัญดูภาพหน้าจอ:

doc dropdown ค่าต่างๆ 2

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

doc dropdown ค่าต่างๆ 3

3. ใน การตรวจสอบข้อมูล ภายใต้ การตั้งค่า เลือกแท็บ รายการ จาก อนุญาต เลื่อนลงจากนั้นคลิก doc dropdown ค่าต่างๆ 5 เพื่อเลือกรายการชื่อที่คุณต้องการใช้เป็นค่าแบบเลื่อนลงในไฟล์ แหล่ง กล่องข้อความ. ดูภาพหน้าจอ:

doc dropdown ค่าต่างๆ 4

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

รหัส VBA: แสดงค่าที่แตกต่างจากรายการแบบหล่นลง:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    selectedNa = Target.Value
    If Target.Column = 5 Then
        selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
        If Not IsError(selectedNum) Then
            Target.Value = selectedNum
        End If
    End If
End Sub

doc dropdown ค่าต่างๆ 6

หมายเหตุ: ในรหัสด้านบนหมายเลข 5 ภายใน ถ้า Target.Column = 5 แล้ว สคริปต์คือหมายเลขคอลัมน์ที่รายการแบบเลื่อนลงของคุณตั้งอยู่ซึ่งเป็น "หล่นลง" ในเรื่องนี้ selectedNum = Application.VLookup (selectedNa, ActiveSheet.Range ("dropdown"), 2, False) รหัสคือชื่อช่วงที่คุณสร้างขึ้นในขั้นตอนที่ 1 คุณสามารถเปลี่ยนเป็นชื่อที่ต้องการได้

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

doc dropdown ค่าต่างๆ 7


การสาธิต: สร้างรายการแบบหล่นลง แต่แสดงค่าที่แตกต่างกันใน Excel

Kutools สำหรับ Excel: ด้วย Add-in ของ Excel ที่มีประโยชน์มากกว่า 300 รายการให้ทดลองใช้ฟรีโดยไม่มีข้อ จำกัด ใน 30 วัน ดาวน์โหลดและทดลองใช้ฟรีทันที!

 

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

🤖 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 (44)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello everyone,

About two years ago, @skyyang posted the following formula, which works perfectly:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


However, I have six sections each needing the same results from the DDL name range. How do I get this formula to apply to more than one column please?

Any help would be greatly appreciated 🙂
This comment was minimized by the moderator on the site
How can I use this formula if the data for the drop down is on a sheet named materials?

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("Material_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
This comment was minimized by the moderator on the site
Can this be applied to certain cells only instead of the whole column? It’s coming back as #N/A for some areas that i don't need this formula for. Thanks
This comment was minimized by the moderator on the site
The code I have used is below:


Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 8 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("codes"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub



This works exactly how I need it too, however, when I save, close and then re-open the excel document, this has disappeared from the 'View Code' window and I have to re-insert the code again?????

Please help!
This comment was minimized by the moderator on the site
I have even saved the document as a Excel Macro-Enabled Workbook
This comment was minimized by the moderator on the site
Can you do multiple drop down lists like this on the same worksheet tab? How will the vba code be adjusted to accommodate different lists for the sheet?
This comment was minimized by the moderator on the site
Is there a way to return multiple selections to the same field? I.E. I want to show the numbers for Tedi, Dave and Lucy on a single field seperated by a comma.Many thanks.
This comment was minimized by the moderator on the site
This works for me but is there a way to allow multiple selections in the same cell? I.e. I wanted to return the numbers for Tedi, Lucy and Dave in a single field seperated by a comma?
This comment was minimized by the moderator on the site
Can this be done on different sheets? I mean, on sheet1 the range and on sheet2 the dropdown. How do I have to code this? Thanks.
This comment was minimized by the moderator on the site
Hello, Muhammd,To apply the drop down list in different worksheet, the following code may help you:Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


Please try, thank you!
This comment was minimized by the moderator on the site
trying to do multiple drop downs sheet 1 , returning different worksheet. Is this possible as when i select in separate dropdown the sam numbers it does not work For example
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice

selectedNa = Target.Value
If Target.Column = 2 Then
Set xRg = ActiveWorkbook.Names("Supervisors").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value
End If
End If
selectedNa = Target.Value
If Target.Column = 9 Then
Set xRg = ActiveWorkbook.Names("Earth").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value

End If
End If
End Sub
This comment was minimized by the moderator on the site
Good morning i hope someone can help me.I used the VBA code above and it worked perfectly giving me my drop down showing me Different Values In Drop Down List Cell.My problem is that I need a second drop down list showing different values in a second list cell, on the same sheet, can anyone help me in doing this Kind Regards Rene
This comment was minimized by the moderator on the site
Se pueden usar diferentes “dropdown” en la misma hoja, para diferentes columnas y con diferentes rangos?Me explico, tengo una hoja en la que los usuarios introducen diferentes datos. En dos columnas 5 y 12 necesito validar la entrada con respecto a dos rangos diferentes de datos. Lo he probado solo con una columna y funciona perfectamente, pero no encuentro la manera de modificar el código VBA para la segunda columna
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