Sub FirstMacro()
Dim sh As Worksheet, ws As Worksheet, sh2 As Worksheet
Dim gp1 As Range, gp2 As Range, gp3 As Range, gp4 As Range
Dim rng As Range, c As Range
Dim rw, cl, x
Dim CntRng As Range
Set sh = Sheets("groups")
Set ws = Sheets("data")
Set sh1 = Sheets("candidates")
With sh1
Set CntRng = .Range("C:C,H:H")
End With
With sh
Set gp1 = .Cells.Find("Group 1")
Set gp2 = .Cells.Find("Group 2")
Set gp3 = .Cells.Find("Group 3")
Set gp4 = .Cells.Find("Group 4")
.Range("D7:F61,J7:L61,J28:L82,D28:F82").ClearContents
.Pictures.Delete
End With
x = 2
With ws
Set rng = .Range("D2:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
For Each c In rng.Cells
Set ct = CntRng.Find(c.Offset(, -1), LookIn:=xlValues)
If Not ct Is Nothing Then
If c = "Group 1" Then
rw = gp1.Row + 1
cl = gp1.Column + 3
sh.Cells(rw + x, cl) = c.Offset(, -1) 'admin number
'sh.Cells(rw + x, cl - 1) = c.Offset(, -2) 'name
sh.Cells(rw + x, cl + 1) = c.Offset(, 2) 'score
x = x + 2
End If
End If
Next c
x = 2
For Each c In rng.Cells
Set ct = CntRng.Find(c.Offset(, -1), LookIn:=xlValues)
If Not ct Is Nothing Then
If c = "Group 2" Then
rw = gp2.Row + 1
cl = gp2.Column + 3
sh.Cells(rw + x, cl) = c.Offset(, -1) 'admin number
'sh.Cells(rw + x, cl - 1) = c.Offset(, -2) 'name
sh.Cells(rw + x, cl + 1) = c.Offset(, 2) 'score
x = x + 2
End If
End If
Next c
x = 2
For Each c In rng.Cells
Set ct = CntRng.Find(c.Offset(, -1), LookIn:=xlValues)
If Not ct Is Nothing Then
If c = "Group 3" Then
rw = gp3.Row + 1
cl = gp3.Column + 3
sh.Cells(rw + x, cl) = c.Offset(, -1) 'admin number
'sh.Cells(rw + x, cl - 1) = c.Offset(, -2) 'name
sh.Cells(rw + x, cl + 1) = c.Offset(, 2) 'score
x = x + 2
End If
End If
Next c
x = 2
For Each c In rng.Cells
Set ct = CntRng.Find(c.Offset(, -1), LookIn:=xlValues)
If Not ct Is Nothing Then
If c = "Group 4" Then
rw = gp4.Row + 1
cl = gp4.Column + 3
sh.Cells(rw + x, cl) = c.Offset(, -1) 'admin number
'sh.Cells(rw + x, cl - 1) = c.Offset(, -2) 'name
sh.Cells(rw + x, cl + 1) = c.Offset(, 2) 'score
x = x + 2
End If
End If
Next c
End With
SecondMacro
End Sub
Sub SecondMacro()
Dim sh As Worksheet, ws As Worksheet
Dim rng As Range, c As Range
Dim fndRng As Range
Set sh = Sheets(2)
Set ws = Sheets(1)
With sh
Set rng = .Range("E:E,K:K").SpecialCells(xlCellTypeConstants, 1)
For Each c In rng.Cells
With ws
Set fndRng = .Cells.Find(c, LookIn:=xlValues)
If Not fndRng Is Nothing Then
fndRng.Offset(, 1).Copy c.Offset(, -2)
End If
End With
Next c
End With
End Sub
Bookmarks