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

วิธีการ vlookup คืนค่าหลายค่าในเซลล์เดียวใน Excel

โดยปกติใน Excel เมื่อคุณใช้ฟังก์ชัน VLOOKUP หากมีค่าหลายค่าที่ตรงกับเกณฑ์คุณก็จะได้ค่าแรก แต่บางครั้งคุณต้องการส่งคืนค่าที่สอดคล้องกันทั้งหมดที่ตรงตามเกณฑ์ลงในเซลล์เดียวตามภาพหน้าจอต่อไปนี้คุณจะแก้ไขได้อย่างไร

Vlookup เพื่อคืนค่าหลายค่าลงในเซลล์เดียวด้วยฟังก์ชัน TEXTJOIN (Excel 2019 และ Office 365)

Vlookup เพื่อส่งคืนค่าหลายค่าในเซลล์เดียวด้วย User Defined Function

Vlookup เพื่อส่งคืนค่าหลายค่าในเซลล์เดียวด้วยคุณสมบัติที่มีประโยชน์


Vlookup เพื่อคืนค่าหลายค่าลงในเซลล์เดียวด้วยฟังก์ชัน TEXTJOIN (Excel 2019 และ Office 365)

หากคุณมี Excel เวอร์ชันที่สูงกว่าเช่น Excel 2019 และ Office 365 มีฟังก์ชันใหม่ - ข้อความเข้าร่วมด้วยฟังก์ชันที่ทรงพลังนี้คุณสามารถ vlookup และคืนค่าที่ตรงกันทั้งหมดลงในเซลล์เดียวได้อย่างรวดเร็ว

Vlookup เพื่อส่งคืนค่าที่ตรงกันทั้งหมดลงในเซลล์เดียว

กรุณาใช้สูตรด้านล่างในเซลล์ว่างที่คุณต้องการใส่ผลลัพธ์จากนั้นกด Ctrl + Shift + Enter คีย์เข้าด้วยกันเพื่อให้ได้ผลลัพธ์แรกจากนั้นลากที่จับเติมลงไปที่เซลล์ที่คุณต้องการใช้สูตรนี้และคุณจะได้รับค่าที่เกี่ยวข้องทั้งหมดตามภาพด้านล่างที่แสดง:

=TEXTJOIN(",",TRUE,IF($A$2:$A$11=E2,$C$2:$C$11,""))

หมายเหตุ ในสูตรข้างต้น A2: A11 คือช่วงการค้นหามีข้อมูลการค้นหา E2 คือค่าการค้นหา C2: C11 คือช่วงข้อมูลที่คุณต้องการส่งคืนค่าที่ตรงกัน ","เป็นตัวคั่นในการแยกหลายระเบียน

Vlookup เพื่อส่งคืนค่าที่ตรงกันทั้งหมดโดยไม่ซ้ำกันในเซลล์เดียว

หากคุณต้องการส่งคืนค่าที่ตรงกันทั้งหมดตามข้อมูลการค้นหาโดยไม่ซ้ำกันสูตรด้านล่างอาจช่วยคุณได้

กรุณาคัดลอกและวางสูตรต่อไปนี้ลงในเซลล์ว่างจากนั้นกด Ctrl + Shift + Enter คีย์เข้าด้วยกันเพื่อให้ได้ผลลัพธ์แรกจากนั้นคัดลอกสูตรนี้เพื่อเติมเซลล์อื่น ๆ และคุณจะได้รับค่าที่เกี่ยวข้องทั้งหมดโดยไม่ต้องมีค่าที่ไม่ชัดเจนดังภาพด้านล่างที่แสดง:

=TEXTJOIN(",", TRUE, IF(IFERROR(MATCH($C$2:$C$11, IF(E2=$A$2:$A$11, $C$2:$C$11, ""), 0),"")=MATCH(ROW($C$2:$C$11), ROW($C$2:$C$11)), $C$2:$C$11, ""))

หมายเหตุ ในสูตรข้างต้น A2: A11 คือช่วงการค้นหามีข้อมูลการค้นหา E2 คือค่าการค้นหา C2: C11 คือช่วงข้อมูลที่คุณต้องการส่งคืนค่าที่ตรงกัน ","เป็นตัวคั่นในการแยกหลายระเบียน

Vlookup เพื่อส่งคืนค่าหลายค่าในเซลล์เดียวด้วย User Defined Function

ฟังก์ชัน TEXTJOIN ข้างต้นพร้อมใช้งานสำหรับ Excel 2019 และ Office 365 เท่านั้นหากคุณมี Excel เวอร์ชันอื่น ๆ ที่ต่ำกว่าคุณควรใช้รหัสบางอย่างเพื่อทำงานนี้ให้เสร็จ

Vlookup เพื่อส่งคืนค่าที่ตรงกันทั้งหมดลงในเซลล์เดียว

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

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

รหัส VBA: Vlookup เพื่อส่งคืนค่าหลายค่าในเซลล์เดียว

Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String = ",") As Variant
'Updateby Extendoffice
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
    ConcatenateIf = CVErr(xlErrRef)
    Exit Function
End If
For i = 1 To CriteriaRange.Count
    If CriteriaRange.Cells(i).Value = Condition Then
        xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
    End If
Next i
If xResult <> "" Then
    xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf = xResult
Exit Function
End Function

3. จากนั้นบันทึกและปิดรหัสนี้กลับไปที่แผ่นงานและป้อนสูตรนี้: =CONCATENATEIF($A$2:$A$11, E2, $C$2:$C$11, ", ") ลงในเซลล์ว่างที่คุณต้องการวางผลลัพธ์จากนั้นลากที่จับเติมลงเพื่อรับค่าที่เกี่ยวข้องทั้งหมดในเซลล์เดียวที่คุณต้องการดูภาพหน้าจอ:

หมายเหตุ ในสูตรข้างต้น A2: A11 คือช่วงการค้นหามีข้อมูลการค้นหา E2 คือค่าการค้นหา C2: C11 คือช่วงข้อมูลที่คุณต้องการส่งคืนค่าที่ตรงกัน ","เป็นตัวคั่นในการแยกหลายระเบียน

Vlookup เพื่อส่งคืนค่าที่ตรงกันทั้งหมดโดยไม่ซ้ำกันในเซลล์เดียว

หากต้องการละเว้นรายการที่ซ้ำกันในค่าการจับคู่ที่ส่งคืนโปรดดำเนินการกับรหัสด้านล่าง

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

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

รหัส VBA: Vlookup และส่งคืนค่าที่ตรงกันที่ไม่ซ้ำกันหลายค่าในเซลล์เดียว

Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer)
'Updateby Extendoffice
    Dim xDic As New Dictionary
    Dim xRows As Long
    Dim xStr As String
    Dim i As Long
    On Error Resume Next
    xRows = LookupRange.Rows.Count
    For i = 1 To xRows
        If LookupRange.Columns(1).Cells(i).Value = Lookupvalue Then
            xDic.Add LookupRange.Columns(ColumnNumber).Cells(i).Value, ""
        End If
    Next
    xStr = ""
    MultipleLookupNoRept = xStr
    If xDic.Count > 0 Then
        For i = 0 To xDic.Count - 1
            xStr = xStr & xDic.Keys(i) & ","
        Next
        MultipleLookupNoRept = Left(xStr, Len(xStr) - 1)
    End If
End Function

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

4. จากนั้นคลิก OK เพื่อปิดกล่องโต้ตอบบันทึกและปิดหน้าต่างรหัสกลับไปที่แผ่นงานและป้อนสูตรนี้: =MultipleLookupNoRept(E2,$A$2:$C$11,3) into a blank cell where you want to output the result, and then drag the fill hanlde down to get all matching values, see screenshot:

หมายเหตุ ในสูตรข้างต้น A2: C11 คือช่วงข้อมูลที่คุณต้องการใช้ E2 คือค่าการค้นหาตัวเลข 3 คือหมายเลขคอลัมน์ที่มีค่าที่ส่งคืน

Vlookup เพื่อส่งคืนค่าหลายค่าในเซลล์เดียวด้วยคุณสมบัติที่มีประโยชน์

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

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

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

1. เลือกช่วงข้อมูลที่คุณต้องการรวมข้อมูลหนึ่งคอลัมน์โดยยึดตามคอลัมน์อื่น

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

3. ในการโผล่ออกมา แถวรวมขั้นสูง กล่องโต้ตอบ:

  • คลิกชื่อคอลัมน์หลักที่จะรวมกันโดยยึดตามแล้วคลิก คีย์หลัก
  • จากนั้นคลิกคอลัมน์อื่นที่คุณต้องการรวมข้อมูลตามคอลัมน์หลักแล้วคลิก รวมกัน เพื่อเลือกตัวคั่นหนึ่งตัวสำหรับแยกข้อมูลที่รวมกัน

4. จากนั้นคลิก OK และคุณจะได้รับผลลัพธ์ดังต่อไปนี้:

ดาวน์โหลดและทดลองใช้ Kutools for Excel ฟรีทันที!


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

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

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

🤖 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 (43)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have created a problem.
"I" have combined a "Textjoin" end "Vlookup" to return multiple values in to one single cell.
My problem is that the formula have to have an exact value to look for and I want it to lookup an "almost" match or Partial match.

Example: I have made a schedule how we ate going to work and a D1 is working from 07:30-16:00. And to lookup D1 is not the problem, the problem is that my boss sometimes puts other stuff togeather with the D1... Like "D1 +" or "D1 meeting".
Since my formula only lookup "D1" it misses for example the "D1 +".

My formula (that I have gotten from the web) =TEXTJOIN(" och ";SANT;OM($B$3:$B$15=$C$22:$F$22;$A$3:$A$15;""))It´s in swedish so "SANT" is "TRUE" and "OM" is "IF".

How can I make the formula lookup all the cells that have some form of "D1" in it and return all those to the same cell?
No matter if it says "D1 +" or "D1 meeting" or whatever.
The reson I want this, is because the boss always leave "D1" but can add other text behind the "D1"... and just because of that, my boss messes up my formula.
This comment was minimized by the moderator on the site
Hi!
This is a great VBA-Code which could help me a lot.But when I start the Function MultipleLookupNoRept Excel crashs...I´ve got a Dataset with about 6.000 Rows (Excel 2013).... is this too much for the VBA Function?

Thanks!
This comment was minimized by the moderator on the site
Hello Mr.XXL,Sorry to hear that. The row limit for Excel 2013 is 1048576. Therefore, maybe the VBA code is the reason for the crash.
Anyway, I would love to offer you another VBA code for Vlookup To Return All Matching Values Without Duplicates Into One Cell. Please use the VBA code below:
Option Explicit

Function Lookup_concat(Search_string As String, _
Search_in_col As Range, Return_val_col As Range)

Dim i As Long
Dim temp() As Variant
Dim result As String
ReDim temp(0)

For i = 1 To Search_in_col.Count
If Search_in_col.Cells(i, 1) = Search_string Then
temp(UBound(temp)) = Return_val_col.Cells(i, 1).Value
ReDim Preserve temp(UBound(temp) + 1)
End If
Next

If temp(0) <> "" Then
ReDim Preserve temp(UBound(temp) - 1)
Unique temp
For i = LBound(temp) To UBound(temp)
result = result & " " & temp(i)
Next i
Lookup_concat = Trim(result)
Else
Lookup_concat = ""
End If

End Function

Function Unique(tempArray As Variant)

Dim coll As New Collection
Dim Value As Variant

On Error Resume Next
For Each Value In tempArray
If Len(Value) > 0 Then coll.Add Value, CStr(Value)
Next Value
On Error GoTo 0

ReDim tempArray(0)

For Each Value In coll
tempArray(UBound(tempArray)) = Value
ReDim Preserve tempArray(UBound(tempArray) + 1)
Next Value

End Function

After you insert this VBA code in the Module, please type the formula =Lookup_concat(E2,$A$2:$A$14,$C$2:$C$14) into a blank cell where you want to output the result, and then drag the fill hanlde down to get all matching values. Please see the file I uploaded in this comment. Hope it solves your problem. 
Sincerely,Mandy

This comment was minimized by the moderator on the site
Hi, Thanks so much this worked!I used it to pull dates, that populated in the serial number format (<span style="letter-spacing: 0.2px; color: inherit; font-family: inherit; font-style: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;">Changing the format to short date format using =TEXT(A2,”mm/dd/yy”) OR =DATEVALUE(A2) are not working. Do you have any solutions?</span>
This comment was minimized by the moderator on the site
Thank you for the explanations, however the function 'MultipleLookupNoRept' does not work on my file, could you tell me if an error exists.
This comment was minimized by the moderator on the site
Hi, Hasnae,Please check if you miss the third step -  check Microsoft Scripting Runtime option in the Available References list box.

This comment was minimized by the moderator on the site
Thank you so much for the code. Is there a way I can use the code to look up multiple values from multiple sheets? I tried to combine your function with IFERROR function but it doesn't seem to work.
This comment was minimized by the moderator on the site
Can this be modified to place the sum of those values? Instead of (400 400 400 400 400 400), can it sum them to show (2400)?
This comment was minimized by the moderator on the site
How with HLookUp function?
This comment was minimized by the moderator on the site
thanks for the code. I have modified it to allow you to optionally specify your own separator, Default is " ", if you specify the separator as"#cr" it will insert a CR/LF so the values will be on a separate line in the cell. It only applies the separator if there are multiple values

Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long, Optional ByVal pSep As Variant)

' ### Returns multiple values from a table into 1 cell ###

' pValue is the key value to lookup

' WorkRng is the Table you want to look up

' pIndex is the column # for the values to be returned from the pWorkRng

' pSep (optional) is the separator to be used. if omitted then default is a space (it doesn't apply the separator for the 1st entry)

' if the separtor = "#cr" it will separate the values on different line in the cell

Dim rng As Range

Dim sSep As String

Dim xResult As String

Dim Item1 As Boolean

Item1 = True



If IsMissing(pSep) = True Then

sSep = vbCr

Else

If pSep = "#cr" Then

sSep = vbCrLf

Else

sSep = pSep

End If

End If



xResult = ""

For Each rng In pWorkRng

If rng = pValue Then

If Item1 Then

xResult = xResult & rng.Offset(0, pIndex - 1)

Item1 = False

Else

xResult = xResult & sSep & rng.Offset(0, pIndex - 1)

End If

End If

Next

MYVLOOKUP = xResult

End Function
This comment was minimized by the moderator on the site
Thank you for this, the line breaks are what i needed to top this formula off! Question, is there a way to modify the code so that two values are compared? For example, similar to what we see with index and match, can i look for Product and Quantity columns, and based on those parameters it outputs results from the Region Column?
This comment was minimized by the moderator on the site
Thanks a lot for this code, it is very helpful. Does anyone know away to sum the values in the cell to just have at total of them.
Cheers
This comment was minimized by the moderator on the site
Hello, James, to sum values based on the corresponding items, the following article may help you, please chek it:
https://www.extendoffice.com/documents/excel/1268-excel-combine-duplicate-rows-and-sum.html
This comment was minimized by the moderator on the site
I have a server, it has connected with multiple applications. I want to compare compare two column and get the related applications details for that server.

What is the command for that.
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