具有多个返回值的VLOOKUP Libre Office VB

问题描述

我正在寻找一个 VLOOKUP 函数,该函数在单元格中返回多个值。有时,您正在搜索的列包含多个值。

例如,我有一个要在Woocommerce中导入的产品列表,这些产品具有变量和变体。我想用所有变量的变体属性列表来填充变量的属性单元格。然后,我在父列中搜索ID,并返回属性列表。

enter image description here

解决方法

这是我发现的东西。

'E2 = searchCell = SKU
'3 = columNumWhereToSearch = Parent
'6 = columnNumWhatToGet = Attribute

Function MULTIPLE_VLOOKUP(searchCell,columNumWhereToSearch,columnNumWhatToGet) As String
    Dim Doc As Object
    Dim Sheet As Object
    Dim Cell As Object   
     
    Doc = ThisComponent
    Sheet = Doc.Sheets(0)

    Dim AttributeListString As String
    AttributeListString = ""
    
    'Set the number of row to search
    For I = 1 To 150
        CellToSearch = Sheet.getCellByPosition(columNumWhereToSearch,I)
        If CellToSearch.String = searchCell then
            CellToGetAndReturn = Sheet.getCellByPosition(columnNumWhatToGet,I).String
            If Len(CellToGetAndReturn) > 0 And CellToGetAndReturn <> "Err:522" And CellToGetAndReturn <> "Err:508" And CellToGetAndReturn <> "#NAME?"  And CellToGetAndReturn <> "#NULL!" And CellToGetAndReturn <> "#VALUE!" And CellToGetAndReturn <> "#REF!" then
                If Len(AttributeListString ) > 0 then
                    AttributeListString = AttributeListString + ","
                End If
                AttributeListString = AttributeListString + CellToGetAndReturn
            End If
        End If
    Next I
    multiple_vlookup = AttributeListString
End Function

=MULTIPLE_VLOOKUP(E2;4;7)

一样使用