Excel “UnCONCATENATE”/explode in function / Convert cell into array

前端 未结 2 1906
不思量自难忘°
不思量自难忘° 2021-01-07 06:38

I am trying to \"Unconcatenate\" a string in Excel 2010. Yes, I know that is not a real word. So pretty much; I have a cell that can not be split into multiple columns the c

2条回答
  •  情话喂你
    2021-01-07 07:15

    (not really an answer, just trying to figure out what the question is)

    Sheet 1 has a dropdown box with a number of items in, the selected item is used in a vlookup() looking at a table in sheet 2.

    Sheet 2 has 2(+) columns, one which is an index used for a vlookup and the other which contains delimited lists.

    Sheet 3 has 1(+) columns, each row has a value that may correspond to an item in one of the delimited lists in sheet 2.

    When an item is selected in the dropdown box on sheet 1 I want to lookup the corresponding list in sheet 2 (using the vlookup) and then see if any of the items in that list exist in sheet 3.

    Is this what your trying to do? If yes, what is the result of this search?

    • Boolean: True-Some matches found!, False-No Matches
    • Number: I found this many results

    No? :(

    Update

    Doing that with just worksheet functions would be fairly tricky!

    VBA is a much better choice. (the final step atleast)

    Add the following code to a new module (not a worksheet or workbook module) and it will be available as a UDF on your worksheets.

    This function takes a string (which is your delimited list) it is exploded inside the function so you dont have to worry about doing it.

    I've not tested it, but in theory it should allow you to pass it a list. The function then should check sheet 3 for you and return true/false depending on weather the items are found or not.

    I know that you've found an answer, but here is a working and slightly faster version of my function.

    Public Function ValidateList(ByVal Target As Range) As Boolean
    Dim Sheet As Worksheet: Set Sheet = ThisWorkbook.Worksheets("Sheet3") ' Check Sheet3 is the correct sheet
    Dim List As Variant: List = Sheet.UsedRange.Columns("A").Value2       ' Set Column(A) to correct column
    Dim Items() As String: Items = Split(Target.Value2, ",")
    Dim Item As Long
    Dim Key As String
    Dim Result As Boolean: Result = False
    Dim Search As Object: Set Search = CreateObject("Scripting.Dictionary")
    
    For Item = LBound(Items) To UBound(Items)
        Search.Add Trim(Items(Item)), False
    Next Item
    
    If Search.Count > 0 Then
        ' Target List has 1+ Items
        For Item = LBound(List, 1) To UBound(List, 1)
            Key = Trim(List(Item, 1))
            If Search.Exists(Key) = True Then
                Search.Remove Key
            End If
            If Search.Count = 0 Then
                Result = True
                Exit For
            End If
        Next Item
    Else
        ' Target List is Empty
        ' Optionally set result to True here if empty list should return True
        ' Defaults to False
    End If
    
    ValidateList = Result
    
    End Function
    

提交回复
热议问题