vlookup在一个单元格中的多个值

时间:2017-10-02 12:10:13

标签: excel vba excel-vba excel-formula

我正在尝试根据来自另一个单元格的选择在一个单元格中查找多个值。

我有下表,我选择一个"健身房" " GymIDs"自动填充。然后我使用下面的VBA让我选择多个" Gyms",我也想让它向我展示多个" GymIDs"。

当前vlookup = VLOOKUP(M7,忽略!F1:G300,2,FALSE)

for some reason I could only upload one image so put them all together

excel table

多个选择的VBA代码

     # X.Org X11 Autotools macros - Dist: CentOS 7.4.1708 for x86_64
    wget ftp://195.220.108.108/linux/centos/7.4.1708/os/x86_64/Packages/xorg-x11-util-macros-1.19.0-3.el7.noarch.rpm
    sudo yum install ./xorg-x11-util-macros-1.19.0-3.el7.noarch.rpm -y

1 个答案:

答案 0 :(得分:0)

我建议在查阅列中编写一个函数。由于您没有提供vlookup,我会将该部分留给您。这里的主要概念是检测Gyms列是单个值还是以逗号分隔的列表,并根据它进行处理:

Public Function GymLookup(ByVal stringToProcess As String) As Variant
Application.Volatile

Dim var As Variant
Dim arrData As Variant
Dim strConcat As String

If InStr(1, stringToProcess, ",") > 0 Then
    arrData = Split(stringToProcess, ",")
    For Each var In arrData
        'multiple handler
        If strConcat = "" Then
            strConcat = "enter your vlookup to resolve a result here"
        Else
            strConcat = strConcat & ", " & "enter your vlookup to resolve a result here"
        End If
    Next var
    GymLookup = strConcat
Else
    'Single cell lookup
    GymLookup = "enter your vlookup to resolve a result here"
End If

End Function
相关问题