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

วิธี vlookup และเชื่อมต่อหลายค่าที่เกี่ยวข้องใน Excel

อย่างที่เราทราบกันดีว่าไฟล์ Vlookup ได้ ฟังก์ชันใน Excel สามารถช่วยให้เราค้นหาค่าและส่งคืนข้อมูลที่เกี่ยวข้องในคอลัมน์อื่นได้ แต่โดยทั่วไปแล้วจะสามารถรับค่าสัมพัทธ์แรกได้ก็ต่อเมื่อมีข้อมูลที่ตรงกันหลายรายการ ในบทความนี้ฉันจะพูดถึงวิธี vlookup และเชื่อมต่อค่าที่เกี่ยวข้องหลายค่าในเซลล์เดียวหรือรายการแนวตั้ง

Vlookup และส่งคืนค่าที่ตรงกันหลายค่าในแนวตั้งด้วยสูตร

Vlookup และเชื่อมต่อค่าที่ตรงกันหลายค่าในเซลล์ด้วย User Defined Function

Vlookup และเชื่อมต่อค่าที่ตรงกันหลายค่าในเซลล์ด้วย Kutools for Excel


สมมติว่าฉันมีช่วงข้อมูลต่อไปนี้เพื่อให้ได้ค่าที่เกี่ยวข้องทั้งหมดตามค่าเฉพาะในแนวตั้งตามภาพหน้าจอต่อไปนี้คุณสามารถใช้สูตรอาร์เรย์ได้

doc vlookup ต่อกัน 1

1. ใส่สูตรนี้: =IF(COUNTIF($A$1:$A$16,$D$2)>=ROWS($1:1),INDEX($B$1:$B$16,SMALL(IF($A$1:$A$16=$D$2,ROW($1:$16)),ROW(1:1))),"") ลงในเซลล์ว่างที่คุณต้องการใส่ผลลัพธ์ตัวอย่างเช่น E2 แล้วกด Ctrl + Shift + Enter คีย์เข้าด้วยกันเพื่อรับค่าสัมพัทธ์ตามเกณฑ์เฉพาะดูภาพหน้าจอ:

doc vlookup ต่อกัน 2

หมายเหตุ: ในสูตรข้างต้น:

A1: A16 คือช่วงคอลัมน์ที่มีค่าเฉพาะที่คุณต้องการค้นหา

D2 ระบุค่าเฉพาะที่คุณต้องการ vlookup

B1: B16 คือช่วงคอลัมน์ที่คุณต้องการส่งคืนข้อมูลที่เกี่ยวข้อง

$ 1: $ 16 ระบุการอ้างอิงแถวภายในช่วง

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

doc vlookup ต่อกัน 3


แทนที่จะรับค่าสัมพัทธ์ในแนวตั้งบางครั้งคุณต้องการให้ค่าที่ตรงกันลงในเซลล์เดียวและเชื่อมต่อด้วยตัวคั่นเฉพาะ ในกรณีนี้ฟังก์ชันที่กำหนดโดยผู้ใช้ต่อไปนี้อาจช่วยคุณได้

1. ค้างไว้ ALT + F11 คีย์เพื่อเปิด Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ โมดูล หน้าต่าง.

รหัส VBA: Vlookup และเชื่อมต่อค่าที่ตรงกันหลายค่าในเซลล์

Function CusVlookup(lookupval, lookuprange As Range, indexcol As Long)
'updateby Extendoffice
Dim x As Range
Dim result As String
result = ""
For Each x In lookuprange
    If x = lookupval Then
        result = result & " " & x.Offset(0, indexcol - 1)
    End If
Next x
CusVlookup = result
End Function

3. จากนั้นบันทึกและปิดรหัสนี้กลับไปที่แผ่นงานและป้อนสูตรนี้: = cusvlookup (D2, A1: B16,2) ลงในเซลล์ว่างที่คุณต้องการใส่ผลลัพธ์แล้วกด เข้าสู่ คีย์ค่าที่เกี่ยวข้องทั้งหมดตามข้อมูลเฉพาะได้ถูกส่งกลับไปยังเซลล์เดียวพร้อมตัวคั่นช่องว่างดูภาพหน้าจอ:

doc vlookup ต่อกัน 4

หมายเหตุ: ในสูตรข้างต้น: D2 ระบุค่าเซลล์ที่คุณต้องการค้นหา A1: B16 คือช่วงข้อมูลที่คุณต้องการดึงข้อมูลจำนวน 2 คือหมายเลขคอลัมน์ที่จะส่งคืนค่าที่ตรงกันคุณสามารถเปลี่ยนการอ้างอิงเหล่านี้ตามความต้องการของคุณ


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

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

หลังจากการติดตั้ง Kutools สำหรับ Excelโปรดดำเนินการดังนี้:

1. เลือกช่วงข้อมูลที่คุณต้องการรับค่าที่สอดคล้องกันตามข้อมูลที่ระบุ

2. จากนั้นคลิก Kutools > ผสานและแยก > แถวรวมขั้นสูงดูภาพหน้าจอ:

3. ใน แถวรวมขั้นสูง กล่องโต้ตอบคลิกชื่อคอลัมน์ที่คุณต้องการรวมจากนั้นคลิก คีย์หลัก ปุ่มดูภาพหน้าจอ:

doc vlookup ต่อกัน 6

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

doc vlookup ต่อกัน 7

5. จากนั้นคลิก Ok ค่าที่เกี่ยวข้องทั้งหมดตามค่าเดียวกันได้ถูกรวมเข้าด้วยกันโดยใช้ตัวคั่นเฉพาะดูภาพหน้าจอ:

doc vlookup ต่อกัน 8 2 doc vlookup ต่อกัน 9

 ดาวน์โหลดและทดลองใช้ Kutools for 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 (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Is there any way to get the unique "name" for "class1"
This comment was minimized by the moderator on the site
Hello, sym-john,
Maybe the below article can solve your problem, please view it:
https://www.extendoffice.com/documents/excel/3381-excel-extract-unique-values-with-criteria.html
This comment was minimized by the moderator on the site
This is working great for me - is there anyway to change it that it checks if the cell contains rather than a complete match? Basically I have a list of tasks where:
Column A: Dependencies (eg 10003 10004 10008)
Column B: Task Reference (eg 10001)
Column C: Dependent Tasks (the column for the formula result) - where it would lookup the task reference to see which rows contain it in Column A, and then list the Task Reference of those tasks.

E.g:

Row | Column A | Column B | Column C
1 | | 10001 | 10002 10003
2 | 10001 | 10002 | 10003
3 | 10001 10002 | 10003 |
This comment was minimized by the moderator on the site
you would want to use the Instr() function which will check for something in a string of text in a cell. You can also use Left() and Right() if you are looking for the starting or ending details.
This comment was minimized by the moderator on the site
The cusVlookup worked great for me. Another way to have a different separator is to wrap in two substitute functions. The first (from inside to out) replaces the first space with no space, the second replaces all other spaces with a " / " in mine. Could use "," if you want commas.
=SUBSTITUTE(SUBSTITUTE(cusVlookup(D2,Table1,2)," ","",1)," "," / ")

Also, if your lookup value isn't the first column, you can use 0 or negative numbers to go to column to the left.
=SUBSTITUTE(SUBSTITUTE(cusVlookup(D2,Table1,-1)," ","",1)," "," / ")
This comment was minimized by the moderator on the site
Hi, jeff,
Thanks for your sharing, you must be a warmhearted man.
This comment was minimized by the moderator on the site
I have to say, I have been trying to get a formula for combining multiple values and returning them to a single cell for 2 days now. This "How To" has saved me!! Thank you SO much! I would never have gotten it without your Module!
I do have 2 questions though. I have the deliminator as a comma instead of a space and because of that it starts out with a comma. Is there a way to prevent the start comma but keep the rest?
My second question is; When I use the fill handle it changes the range values as well as the cell value I want to look up. I want it to continue to change the cell number I want to look up but keep the same range values. How can I make this happen?

Thank you so much for your help!!
This comment was minimized by the moderator on the site
Is there a way to delete the duplicate values in the concatenate?
This comment was minimized by the moderator on the site
Hello, Jacob,
May be the following article can help you to solve your problem.
https://www.extendoffice.com/documents/excel/3381-excel-extract-unique-values-with-criteria.html

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Is there a way to list the duplicate values only once, using the vba code and formula above? I am not sure where to put the countif>1 statement in the formula bar, or in the vba itself. Please help
This comment was minimized by the moderator on the site
you can add two extra condition to skip blank cells and to skip duplicates:For i = 1 To CriteriaRange.Count
If CriteriaRange.Cells(i).Value = Condition Then
If ConcatenateRange.Cells(i).Value <> "" Then 'SKIP BANKS
If InStr(xResult, ConcatenateRange.Cells(i).Value) = 0 Then 'SKIP IF FOUND DUPLICATE
xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
End If
End If
End If
Next i
This comment was minimized by the moderator on the site
This is amazing but i am looking for something else, i have a table with RollNo StudentName sub1, sub2, sub3 ... Total Result, When I enter Rollnumber it should give a result like "SName Sub1 64, sub2 78,... Total 389, Result pass", is it possible
This comment was minimized by the moderator on the site
Loved the function for Excel 2013 but amended it slightly to change the separating character to ";" instead of " " and then remove the prefixed ";" from the concantenated values Results matching values in my example would have ;result01 or ;result01;result02 . Added the extra If Left(xResult, 1) = ";" to remove any extra ";" at the beginning of the string if it is the 1st character. I'm sure there is a neater way of doing it but it worked for me. :) Function CusVlookup(pValue As String, pWorkRng As Range, pIndex As Long) Dim rng As Range Dim xResult As String xResult = "" For Each rng In pWorkRng If rng = pValue Then xResult = xResult & ";" & rng.Offset(0, pIndex - 1) If Left(xResult, 1) = ";" Then xResult = MID(xResult,2,255) End If End If Next CusVlookup = xResult End Function
This comment was minimized by the moderator on the site
Make if condition for result if empty.

Function CusVlookup(lookupval, lookuprange As Range, indexcol As Long)
'updateby Extendoffice 20151118
Dim x As Range
Dim result As String
result = ""
For Each x In lookuprange
If x = lookupval Then
If Not result = "" Then
result = result & " " & x.Offset(0, indexcol - 1)
Else
result = x.Offset(0, indexcol - 1)
End If
Next x
CusVlookup = result
End Function
This comment was minimized by the moderator on the site
When using the cusvlookup is there a way to add the last name as well with a comma in between that might appear in Column C
This comment was minimized by the moderator on the site
How to get the result. Please help. data data1 result a 1 a1 b 2 a2 c b1 b2 c1 c2
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations