У меня есть рабочее решение. Нажмите Alt+, F11чтобы войти в редактор Visual Basic, создать новый модуль и вставить в него этот код. Вы сможете использовать CAT
функцию в любой ячейке, например так:=CAT(category,qualities)
.
' Function that expects a quality and returns the respective code ' Important: Tick check box beside "Microsoft Scripting Runtime" in Tools > References Function lookup_code(ByRef quality) Dim dict As New Scripting.Dictionary dict.Add "Arboricultural", "1" dict.Add "Landscape", "2" dict.Add "Cultural_and_Conservation", "3" lookup_code = dict(quality) End Function ' Function to output the concatenated CAT code ' Use in any Excel cell as `=CAT(category, qualities)` ' Expects a category (e.g. "A") and a string of one or more qualities, separated by a comma Function CAT(category, qualities) Dim code As String If InStr(qualities, ",") > 0 Then ' Check for commas Dim QualityArray() As String QualityArray = Split(qualities, ",") ' Split string at commas For Each q In QualityArray code = code & "," & lookup_code(q) ' match code to quality Next Else code = "," & lookup_code(CStr(qualities)) End If CAT = category & code ' return category and codes (e.g. "B,2,3,1") End Function