Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 将一列中的值与另一列中以逗号分隔的值进行匹配,并返回匹配的值_Google Apps Script_Google Sheets_Spreadsheet_Google Sheets Api - Fatal编程技术网

Google apps script 将一列中的值与另一列中以逗号分隔的值进行匹配,并返回匹配的值

Google apps script 将一列中的值与另一列中以逗号分隔的值进行匹配,并返回匹配的值,google-apps-script,google-sheets,spreadsheet,google-sheets-api,Google Apps Script,Google Sheets,Spreadsheet,Google Sheets Api,我有一列的值如下 himaanshu akshay rahul hgeet axs,fdvf,dasad axs,fdvf,dasad, himaanshu axs,fdvf,dasad, akshay asz,wesd,hgeet 另一列的值如下 himaanshu akshay rahul hgeet axs,fdvf,dasad axs,fdvf,dasad, himaanshu axs,fdvf,dasad, akshay asz,wesd,hgeet 我需要从第1列的整个列表中

我有一列的值如下

himaanshu
akshay
rahul
hgeet
axs,fdvf,dasad
axs,fdvf,dasad, himaanshu
axs,fdvf,dasad, akshay
asz,wesd,hgeet
另一列的值如下

himaanshu
akshay
rahul
hgeet
axs,fdvf,dasad
axs,fdvf,dasad, himaanshu
axs,fdvf,dasad, akshay
asz,wesd,hgeet
我需要从第1列的整个列表中返回第2列中每一行的匹配名称

解决办法应该是:

 1. None
 2. himaanshu
 3. akshay
 4. hgeet
有谁能帮我用电子表格中的公式来解决这个问题。

=VLOOKUP(“*”&A1&“*”,B1:B4,1,0)
尝试以下方法:

Sub test()

    Dim str1 As String
    Dim rngToSearch As Range, cell As Range
    Dim LastRowA As Long, LastrowC As Long, i As Long, y As Long
    Dim arr As Variant

    With ThisWorkbook.Worksheets("Sheet1")

        LastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
        LastrowC = .Cells(.Rows.Count, "C").End(xlUp).Row

        Set rngToSearch = .Range("C2:C" & LastrowC)

        For i = 2 To LastRowA

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

            For Each cell In rngToSearch

                arr = Split(cell.Value, ",")

                For y = LBound(arr) To UBound(arr)

                    If Trim(arr(y)) = Trim(str1) Then
                        .Range("B" & i).Value = str1
                    End If

                Next y

            Next cell

        Next i

    End With

End Sub
结果:

查看此公式是否有效(在谷歌电子表格中)

该公式从C列的值中提取A列的任何值


[/p]你可以从阅读中受益。答案不加解释就发布代码。考虑添加一个解释来改进你的答案。你的回答也不能正确地反映实际问题。想象一下代码> ABC,CDE,FGH 。如果你现在查阅<代码> AB ,即使<代码> AB <代码>也不会出现。逗号分隔的列表。谢谢分享答案。但我只需要返回匹配的值来搜索。如第2行-无第3行-himaanshu第4行-akshay第5行-hgeet@Error想象一下,如果您现在查找
ABC、CDE、FGH
,即使
AB
没有出现在逗号分隔的列表中,它也会匹配。@Pᴇʜ你在写。我将删除答案,如果我找到解决方案,我将删除答案back@Error1004VBA很好,但OP现在指定了google sheets:/我以为VBA也包括在内。我的坏!