get distinct list (index) if adjacent value equals a specific text in excel

浪尽此生 提交于 2019-12-25 08:04:08

问题


I would like to get a distinct list of column J if cell in H of same row equals "No Company".

I tried =IFERROR(INDEX($J$2:$J$10, MATCH(0, COUNTIF($K$1:K2, $J$2:$J$10&"") + IF(ISTEXT($H$2:$H$10)="No company",1,0), 0)), ""))

also tried =IFERROR(INDEX(J$2:J$400, SMALL(IF((H$2:H$400=No company)>1)), ROW(j$2:j$400)-ROW(j$2)+1), ROWS(j$2:j2)), "") changing some of the fields but no luck

Desired result + Try


回答1:


Create a new function: open VBA Editor (alt + F11), add new module, insert code:

Function JoinAll(ByRef range As range, ByVal delimiter As String)
  For Each c In range.Cells
  If InStr(JoinAll, c.Value) = 0 Then
    JoinAll = JoinAll + c.Value + delimiter
  End If
  Next
  JoinAll = Left(JoinAll, Len(JoinAll) - Len(delimiter))
End Function

use formula like this:

=JoinAll(J2:J10, ", ")


来源:https://stackoverflow.com/questions/40166146/get-distinct-list-index-if-adjacent-value-equals-a-specific-text-in-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!