Once the first VBA red codeline corrected according to my post #27 no issue on my side, well works as expected …
Awesome, will test it with my data!!
Once the first VBA red codeline corrected according to my post #27 no issue on my side, well works as expected …
(For example, the school code is not matched, but it still shows a black text color "code".
With the last version of the #27 code, still encounter the same problem (Text color shown as black, but not grey for unmatched "Code"). I used Excel 2019 64 bit, version: 1808 (Build 10357.20081) and attached the file.
When I try it with an Excel for Mac Version: 16.60 (22041000), it works perfectly. I can use the macOS to generate the data, so It may not be an issue anymore. Many thanks!
Const C = 16
Dim Rc As Range, V, oCol As New Collection
Sub ColDic(T$)
Const D = "¤", S = "&""" & D & """&"
Dim K, R&, W, oDic As New MDictionary, A, X, M&, N&
K = Evaluate("{" & T & "}-1")
For R = 1 To UBound(K): K(R) = Rc(K(R)).Address: Next
K = Rc.Parent.Evaluate(Join(K, S))
For R = 1 To Rc.Rows.Count
If V(R, 1) Then
W = oDic(K(R, 1))
If IsArray(W) Then ReDim Preserve W(UBound(W) + 1): W(UBound(W)) = R Else W = Array(R)
oDic(K(R, 1)) = W
End If
Next
K = Evaluate("{" & T & "}")
A = K
With UsedRange.Rows(Cells(Rows.Count, 3).End(xlUp)(2).Row & ":" & UsedRange.Rows.Count).Columns
For R = 1 To UBound(K): K(R) = .Item(K(R)).Address: Next
K = Evaluate(Join(K, S))
For R = 1 To .Rows.Count
If oDic.Exists(K(R, 1)) Then
W = oDic(K(R, 1))
X = Application.Index(V, W)
M = Application.Max(X)
If M Then
N = W(Application.Match(M, X, 0) - 1)
V(N, 1) = M - 1
.Item("C:D").Rows(R) = oCol(N)
.Cells(R, .Count) = 1
Else
oDic.Remove K(R, 1)
End If
End If
Next
If N Then
.Sort .Item(.Count), 1, Header:=2
R = Cells(Rows.Count, 3).End(xlUp).Row
K = [{5,6,7}]
A = Application.Match(K, A, 0)
For N = 1 To UBound(A): A(N) = IIf(IsError(A(N)), Range(Cells(.Row, K(N)), Cells(R, K(N))).Address, D): Next
A = Join(Filter(A, D, False), ",")
If A > "" Then Range(A).Font.ColorIndex = C
End If
End With
End Sub
Sub Demo2()
Dim R&, N&
UsedRange.Clear
With Sheet1
R = .[IF(ISNUMBER(G3),G3,0)]: If R < 1 Then Beep: Exit Sub
Set Rc = .[A1].CurrentRegion.Rows("3:" & .[A1].CurrentRegion.Rows.Count).Columns
V = .Evaluate(Replace("IF(ISNUMBER(#),#," & R & ")", "#", Rc(1)(7).Address))
End With
For R = 1 To Rc.Rows.Count: oCol.Add Rc("A:B").Rows(R).Value: Next
Application.ScreenUpdating = False
[A1:H1] = [{"Mentee ID","Mentee Name","Mentor ID","Mentor Name","Gender","Programme","Code"," "}]
With Sheet2.[A1].CurrentRegion.Rows
.Range("A3:B" & .Count).Copy [A2]
.Range("D3:F" & .Count).Copy [E2]
End With
ColDic "6,7,5" ' Programme & Code & Gender
ColDic "6,7" ' Programme & Code
ColDic "6,5" ' Programme & Gender
ColDic "6" ' Programme
ColDic "7,5" ' Code & Gender
ColDic "7" ' Code
ColDic "5" ' Gender
R = Cells(Rows.Count, 3).End(xlUp)(2).Row
With UsedRange.Rows
If R <= .Count Then ' last mentors to last mentees
.Item(R & ":" & .Count).Columns("E:G").Font.ColorIndex = C
For R = R To .Count
N = Application.Match(Application.Max(V), V, 0)
If V(N, 1) Then V(N, 1) = V(N, 1) - 1 Else Exit For
.Item(R).Columns("C:D") = oCol(N)
Next
End If
.Columns(.Columns.Count).Clear
End With
Application.ScreenUpdating = True
Set Rc = Nothing: Set oCol = Nothing: Erase V
End Sub