具有多个 return 个值的 VLOOKUP Libre Office VB

VLOOKUP with multiple return values Libre Office VB

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

例如,我有一个要导入 Woocommerce 的产品列表,这些产品有变量和变体。我想用其所有变体的属性作为列表填充 Variable 的属性单元格。然后我在 parent 列和 return 属性列表中搜索 ID。

这是我找到的。

'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)

一样使用