Hi DisChordant,
'What I'd like to now create is a spreadsheet the head of year/key stage can use
'that will ask them the year group of the student they are interested in
'and how many amber or red flags they want to look for.
'(E.g. students in Year 7 who have over 4 subjects listed with an R).
Sub DisChord(): Dim SYear As Integer, Flags As String, SName As String, n As Integer
Dim wb As Workbook, ws As Worksheet, wd As Workbook, wc As Worksheet
Dim r As Long, f As Long, i As Long, j As Long, S As String, P As String, U As String:
P = ActiveWorkbook.Path & "\": U = Dir(P)
SYear = Val(InputBox("Student Year Group?"))
Flags = _
InputBox(" Type #, RAO for Number of Flags Red - Amber or Outstanding (Inclusive)")
i = InStr(1, Flags, ","): n = Left(Flags, i - 1)
Set wd = Workbooks("DisChordant") 'The Summary Book Name goes here in the same folder as the others
SetaBook:
If U = wd.Name Then GoTo GetaBook
If InStr(1, U, ".xl") = 0 Then GoTo GetaBook
If InStr(1, U, "Department Summary") Then
Workbooks.Open fileName:=P & U, UpdateLinks:=0
Set wb = ActiveWorkbook: Set ws = wb.Sheets("Sheet1")
If InStr(1, Flags, "O") Then
Set wc = wd.Sheets("Outstanding"): r = GetLine(wc)
ws.Range("A779:U1207").Copy
wc.Range("A" & r).PasteSpecial xlPasteValues: End If
If InStr(1, Flags, "A") Then
Set wc = wd.Sheets("Amber"): r = GetLine(wc)
ws.Range("A405:U777").Copy
wc.Range("A" & r).PasteSpecial xlPasteValues: End If
If InStr(1, Flags, "R") Then
Set wc = wd.Sheets("Red"): r = GetLine(wc)
ws.Range("A3:U403").Copy
wc.Range("A" & r).PasteSpecial xlPasteValues: End If
Application.DisplayAlerts = False
wb.Close SaveChanges:=False
End If
GetaBook: U = Dir() 'Get another book
If U = "" Then GoTo Sorts
GoTo SetaBook
Sorts:
S = wd.Name
Set wc = wd.Sheets("Compilation")
If InStr(1, Flags, "R") Then
r = GetLine(wd.Sheets("Red"))
wd.Sheets("Red").Range("A2:U" & r).Copy
r = GetLine(wc)
wc.Range("A" & r).PasteSpecial xlPasteAll: End If
If InStr(1, Flags, "A") Then
r = GetLine(wd.Sheets("Amber"))
wd.Sheets("Amber").Range("A2:U" & r).Copy
r = GetLine(wc)
wc.Range("A" & r).PasteSpecial xlPasteAll: End If
If InStr(1, Flags, "O") Then
r = GetLine(wd.Sheets("Outstanding"))
wd.Sheets("Outstanding").Range("A2:U" & r).Copy
r = GetLine(wc)
wc.Range("A" & r).PasteSpecial xlPasteAll: End If
r = GetLine(wc)
SortandLoop:
wc.Range("A1:A" & r).Sort Key1:=wc.Range("A2"), _
Order1:=xlAscending, Header:=xlYes
SName = wc.Range("A2")
For i = 2 To r
InLoop:
If wc.Cells(i, 2) = SYear And wc.Cells(i, 1) = SName Then
f = f + 1: i = i + 1: GoTo InLoop: End If
Commentary:
If f >= Flags Then
r = GetLine(wd.Sheets("Sheet1")): wd.Sheets("Sheet1").Cells(r, 1) = SName
wc.Cells(i - j, 18).Copy wd.Sheets("Sheet1").Cells(r, 3 + f)
f = f - 1: j = j + 1: GoTo Commentary: End If
j = 0: r = r + 1: SName = wc.Cells(i + 1, 1)
GetNext: Next i
End Sub
Function GetLine(C As Worksheet) As Long
GetLine = C.Range("A" & Rows.Count).End(xlUp).row + 1: End Function
'I was unable to test the whole routine since I couldn't update the source sheets
'But if you want to send me some Departrment Summary test data, I'll follow through
P.S. The Summary book has 4 extra sheets: Compilation, Red, Amber, Outstanding each with Headers - I'll Attach an example
DisChordant.xlsm
Bookmarks