显示用户的缺失值
我在Excel中有一张表,看起来像这样
role user a Joe b Joe c Joe a Frank
和第二张桌子
role a b c
是否有可能像例子中列出每个用户缺less的angular色?
Frank bc
哇。 这比预期的要困难得多。 不是最优雅的解决scheme。 要求首先对user
列进行sorting,以便所有用户都在一起。
如果role
不止一个字XD,可能不会起作用
Sub wert() Dim roles Dim lastRow As Long Dim fRow As Long Dim user As String Dim except As String Dim list As String user = Application.InputBox("which user?") 'prompt for user With ActiveSheet lastRow = .Cells(.Rows.count, "B").End(xlUp).Row roles = .Range("D2:D4") 'change range as needed With .Range("B2:B" & lastRow) Set f = .Find(user, LookIn:=xlValues, lookat:=xlWhole) 'search for user End With If Not f Is Nothing Then fRow = f.Row 'if found list = .Cells(fRow, 1) For i = fRow To lastRow If .Cells(i + 1, 2) = .Cells(i, 2) Or .Cells(i - 1, 2) = .Cells(i, 2) Then list = list & .Cells(i, 1) 'add role to list 'Debug.Print list Else Exit For End If Next For Each e In roles If InStr(list, e) > 0 Then Else except = except & " " & e 'if role not found in list, then add it to string End If Next .Range("F1").Value = user & ": " & except 'change range if desired End With End Sub