简体   繁体   English

Excel中重复条目的组出现

[英]Group occurences for duplicated entries in Excel

在此处输入图片说明

I have a table with duplicated users from different domains. 我有一个表,其中包含来自不同域的重复用户。 I want to have in a specific cell all the domains a specific user is part of. 我想在特定的单元格中包含特定用户所属的所有域。

Researching and trying to see how I could achieve that, I found TEXTJOIN and IF as a possible option, but for some reason, it is not working as expected. 经过研究并试图了解如何实现这一目标,我发现TEXTJOIN和IF是可能的选择,但由于某些原因,它无法按预期运行。 Instead of show only the tied domains, the formula shows all of them and checking how it works it seems like that would be the result it would return. 该公式不仅显示所有绑定域,而且还显示所有域,并检查其工作原理,好像将返回结果。

I wonder if you know what I am missing here? 我想知道你是否知道我在这里想念什么?

As you will be able to see in the screenshot, for admin it shows the whole array of results and for operator, it shows nothing. 正如您将在屏幕截图中看到的那样,对于admin来说,它显示了整个结果数组;对于operator而言,它什么也不显示。 Not sure why it behaves like that. 不知道为什么会这样。

As expected outcome, considering the attached screenshot I would expect to see in cell F2 only the domains the account admin is part of, so just "aaa". 作为预期的结果,考虑到所附的屏幕截图,我希望在单元格F2中仅看到帐户管理员所属的域,因此仅为“ aaa”。 For operator, "ccc". 对于运算符,“ ccc”。

Appreciate the support in advance. 提前感谢您的支持。

This should be an array formula. 这应该是一个数组公式。 Enter with Ctrl + Shift + Enter . 使用Ctrl + Shift + Enter输入

在此处输入图片说明

try this macro 试试这个宏

Option Explicit
Sub Give_data()
Dim Dict As Object
Dim first As Worksheet
Dim Itm, K, i%: i = 2

 Set Dict = CreateObject("Scripting.Dictionary")
 Set first = Sheets("Sheet1")
 first.Range("E2").CurrentRegion.Offset(1).Resize(, 2).ClearContents
 Do Until first.Range("A" & i) = vbNullString
  K = first.Range("A" & i): Itm = first.Range("B" & i)
     If Not Dict.Exists(K) Then
       Dict.Add K, Itm
       Else
        Dict(K) = Dict(K) & ";" & Itm
      End If
    i = i + 1
  Loop
  With first.Range("E2").Resize(Dict.Count)
    .Value = Application.Transpose(Dict.Keys)
    .Offset(, 1).Value = Application.Transpose(Dict.Items)
  End With
  Dict.RemoveAll: Set Dict = Nothing
  first.Columns("E:F").AutoFit

End Sub

For list all items to the admin,This macro can You Help 列出所有项目给管理员,此宏可以帮助您

Sub My_data() 子My_data()

Dim Dict As Object
Dim first As Worksheet
Dim Itm, K, i%: i = 2
Dim My_String$
 Set Dict = CreateObject("Scripting.Dictionary")
 Set first = Sheets("Sheet1")

 With first
      .Range("E2").CurrentRegion.Offset(1).Resize(, 2).ClearContents
      .Range("E2") = .Range("A2")
     '===============================
     Do Until .Range("B" & i) = vbNullString
      My_String = My_String & ";" & .Range("B" & i)
       i = i + 1
     Loop
       .Range("F2") = Mid(My_String, 2, Len(My_String) - 1)
     '============================
     i = 3
    Do Until .Range("A" & i) = vbNullString
     If .Range("A" & i) = .Range("A2") Then GoTo Next_I
     K = .Range("A" & i): Itm = .Range("B" & i)
        If Not Dict.Exists(K) Then
          Dict.Add K, Itm
          Else
           Dict(K) = Dict(K) & ";" & Itm
         End If
Next_I:
       i = i + 1
     Loop
       With .Range("E3").Resize(Dict.Count)
           .Value = Application.Transpose(Dict.Keys)
           .Offset(, 1).Value = Application.Transpose(Dict.Items)
       End With
  End With
  Dict.RemoveAll: Set Dict = Nothing
  first.Columns("E:F").AutoFit

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM