简体   繁体   English

如何从逗号分隔的单元格中查找多个值并在excel中平均结果?

[英]How do I lookup multiple values from a comma separated cell and average the results in excel?

I'm trying to build a formula that can lookup multiple ISO country codes separated by comma contained in one cell (Cell A2, Image 1) with a reference to a list of country codes and education scoring (Columns F and G, Image 1). 我正在尝试构建一个公式,可以查找由一个单元格(单元格A2,图像1)中包含的逗号分隔的多个ISO国家/地区代码,并引用国家/地区代码和教育评分列表(列F和G,图像1) 。 Then return the average of the scores of all countries on cell B2. 然后返回B2上所有国家/地区的平均得分。 does anyone know if I can build a formula to handle that? 有谁知道我是否可以建立一个公式来处理它? 在此输入图像描述

I didn't think you could do this with cell formula, but then I saw this post and came up with this: 我不认为你可以用细胞配方做到这一点,但后来我看到了这篇文章并想出了这个:

=AVERAGE(IF(ISNA(MATCH($F$2:$F$99, TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(A2)-LEN(SUBSTITUTE(A2,",",""))+1)))=1),99)), 0)), "",  $G$2:$G$99 ))

Try pasting into cell B2 as an array formula (Ctrl + Shift + Enter) and fill-down... And don't ask me how it works. 尝试粘贴到单元格B2作为数组公式(Ctrl + Shift + Enter)和填充...并且不要问我它是如何工作的。

You could try VBA: 你可以试试VBA:

Option Explicit

Sub test()

    Dim i As Long
    Dim strCode As String, strScore As String
    Dim rngVlookup As Range
    Dim Code As Variant

    With ThisWorkbook.Worksheets("Sheet1")

        Set rngVlookup = .Range("F2:G34")

        For i = 2 To 3

        strCode = ""
        strScore = ""

            strCode = .Range("A" & i).Value

            For Each Code In Split(strCode, ",")
                If strScore = "" Then
                    On Error Resume Next
                    strScore = Application.WorksheetFunction.VLookup(Trim(Code), rngVlookup, 2, False)
                Else
                    On Error Resume Next
                    strScore = strScore & ", " & Application.WorksheetFunction.VLookup(Trim(Code), rngVlookup, 2, False)
                End If

            Next Code

            With .Range("B" & i)
                .Value = strScore
                .NumberFormat = "0.000000"
            End With

        Next i

    End With

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在单元格中查找以逗号分隔的多个值并返回以逗号分隔的多个值 - Lookup multiple values separated by a comma in a cell and return multiple values separated by a comma 动态查找单元格中的多个值(逗号分隔)并将相应的 ID 返回到单个单元格(逗号分隔) - Dynamic Lookup for multiple values in a cell (comma separated) and return the corresponding ID to a single cell (comma separated also) 如何匹配逗号分隔的单元格以求和多行的值? - How to match a comma separated cell to sum values from multiple rows? 在单个单元格中查找多个值(以逗号分隔),然后将值返回到单个单元格(也以逗号分隔) - Lookup multiple values in a single cell (separated by commas) and then return the values to a single cell (also comma separated) 将数组中的多个excel值组合回一个单独的excel单元格逗号分隔中 - combine multiple excel values from an array back into a single excel cell comma separated 逗号分隔值的查找公式 - Excel - lookup formula for comma separated Values- Excel excel-如何在Excel中将单元格值转换为逗号分隔值? - How to convert the cell values in comma separated value in excel? 如何计算逗号,另一个单元格Excel中的所有列中的分隔值? - How To Count comma, another cell Separated Values In all Column In Excel? 如何在Excel中的相同/单个单元格中将逗号分隔的值替换为逗号分隔的ID? - How to replace comma separated values to comma separated ids in the same/individual cell in excel? VBA 以逗号分隔返回多个查找值的代码有效,但如果有空单元格则崩溃 - VBA code to return multiple lookup values in one comma separated works but crashes if there's an empty cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM