Frage

I have been asked to figure out how to perform a complex excel function. I'm new to this and am completely stumped :(

I hope you can help.

we have text data on 10,000 lines across 45 columns.

So as an example, in N1 I need a function that looks for words in all cells across row 1.

So if i was to search for "apple" and "pear" and "orange" and "banana", If one or more were found on row 1 then in cell N1 I would like to output "banana, apple" if it found those two words. If nothing was found then it says none.

I've been told this isn't possible but i'm not so sure.

Sorry for the long explanation.

Hope you can assist.

Thanks

War es hilfreich?

Lösung

You can create a Function like:

Public Function SearchBn(ByVal FirstArg As Range, ParamArray OtherArgs()) As String
Dim TmpStr As String
Dim e As Integer

e = 0
TmpStr = ""
For i = LBound(OtherArgs) To UBound(OtherArgs)
    Set c = FirstArg.Find(OtherArgs(i))
    If Not c Is Nothing Then
        If e > 0 Then TmpStr = TmpStr & ", "
        TmpStr = TmpStr & c.Value         ' CHANGE THIS LINE !!!!
        e = e + 1
     End If
Next
If Right(TmpStr, 2) = ", " Then TmpStr = Left(TmpStr, Len(TmpStr) - 2)

If TmpStr = "" Then TmpStr = "*NONE*"
SearchBn = TmpStr

End Function

and call that:

=SearchBn(19:19;D22;D23;D24;D25)

That function accept to the first parameter the range of the cells. The other parameters are what you want to search. You can add how many search criteria you want...
For Excel function:

=IFERROR(HLOOKUP("banana";21:21;1;);"")&", "&IFERROR(HLOOKUP("apple";21:21;1;);"")

If there was and error (not found) write nothing "". Search HLOOKUP a value "banana" in the row 21... the & concatenate the string you found. It's not so friendly, but work... If you want more search you need to add IFERROR ...
To display only the word found, change with:

TmpStr = TmpStr & OtherArgs(i)

You need to put only a cell for the search text, than use ; instead on ,

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top