Hi All,
Have a Volunteer Members Roster spreadsheet that is maintained by several people on a communal SharePoint.
Been manually creating a ERT 7 Day Forecast for years. Time consuming and fraught with error.
Created a series of Macro's to search the Roster and populate the Forecast.
Errors I'm getting is the people are scattered when they appear on Forecast due to the logical way VBA is run.
See Poor Layout vs Correct Layout.
Correct/ Better Layout
Poorer Layout
VBA's below Minisheet
VBA's
Have a Volunteer Members Roster spreadsheet that is maintained by several people on a communal SharePoint.
Been manually creating a ERT 7 Day Forecast for years. Time consuming and fraught with error.
Created a series of Macro's to search the Roster and populate the Forecast.
Errors I'm getting is the people are scattered when they appear on Forecast due to the logical way VBA is run.
See Poor Layout vs Correct Layout.
Correct/ Better Layout
Poorer Layout
VBA's below Minisheet
Mr Excel Test.xlsm | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | |||
1 | QUALIFIED DAYSHIFT | 6 | 6 | 4 | 7 | 3 | 3 | 3 | 3 | 3 | 3 | 6 | 3 | 3 | 3 | 4 | 6 | 6 | 8 | 4 | ||||
2 | TRAINEES DAYSHIFT | 3 | 3 | 3 | 2 | 0 | 0 | 0 | 0 | 0 | 1 | 3 | 3 | 3 | 3 | 3 | 4 | 4 | 4 | 2 | ||||
3 | ||||||||||||||||||||||||
4 | QUALIFIED NIGHTSHIFT | 0 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 1 | 1 | 1 | ||||
5 | TRAINEES NIGHTSHIFT | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | ||||
6 | ||||||||||||||||||||||||
7 | Volunteer Members | Jan-24 | ||||||||||||||||||||||
8 | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Mon | Tue | Wed | Thu | Fri | |||||
9 | Roster | Name | Status | 1-Jan | 2-Jan | 3-Jan | 4-Jan | 5-Jan | 6-Jan | 7-Jan | 8-Jan | 9-Jan | 10-Jan | 11-Jan | 12-Jan | 13-Jan | 14-Jan | 15-Jan | 16-Jan | 17-Jan | 18-Jan | 19-Jan | ||
10 | Panel A | Person A | Captain | D | D | D | D | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | ||
11 | Panel A | Person B | Trained | O | O | O | O | R | R | R | R | R | R | O | O | O | O | O | O | O | O | R | ||
12 | Panel A | Person C | Medic | R | R | R | D | D | D | D | D | D | D | D | R | R | R | R | R | R | N | N | ||
13 | Panel A | Person D | Lv1 Only | D | D | D | D | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | ||
14 | Panel A | Person E | Recruit | D | D | D | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | R | ||
15 | Panel A | Person F | Trained | D | D | D | D | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | ||
16 | Panel A | Person G | Trained | AL | AL | AL | AL | R | R | R | R | R | R | AL | AL | AL | AL | D | D | D | D | R | ||
17 | Panel A | Person H | Trained | D | D | D | D | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | ||
18 | Panel B | Person J | Captain | R | R | R | D | D | D | D | D | D | D | D | R | R | R | R | R | R | D | D | ||
19 | Panel B | Person L | Trained | R | R | R | D | D | D | D | D | D | D | D | R | R | R | R | TR | TR | TR | TR | ||
20 | Team 2 | Person 2 | Recruit | N | N | N | R | R | R | R | R | R | R | D | D | D | D | D | D | D | D | R | ||
21 | Team 3 | Person 3 | Trained | R | R | R | N | N | N | N | N | N | N | R | R | R | R | R | R | R | D | D | ||
22 | Team 3 | Person 5 | Trained | R | N | N | N | N | N | N | N | R | R | R | R | R | R | R | D | D | D | D | ||
23 | Team 3 | Person 6 | Trained | R | AL | AL | AL | AL | AL | AL | AL | R | R | R | R | R | R | R | D | D | D | D | ||
24 | Team 3 | Person 7 | Lv1 Only | R | R | R | N | N | N | N | N | N | N | R | R | R | R | R | R | R | D | D | ||
25 | Team 3 | Person 8 | Recruit | R | N | N | N | N | N | N | N | R | R | R | R | R | R | R | D | D | D | D | ||
26 | Team 4 | Person 11 | Trained | D | D | R | R | R | R | R | R | AL | AL | AL | AL | AL | AL | AL | R | R | R | R | ||
27 | Team 4 | Person 12 | Trained | D | D | R | R | R | R | R | R | N | N | N | N | N | N | N | R | R | R | R | ||
28 | Team 4 | Person 13 | Trained | D | D | D | D | R | R | R | R | R | R | N | N | N | N | N | N | N | R | R | ||
29 | Team 4 | Person 14 | Lv1 Only | D | D | D | D | R | R | R | R | R | R | N | N | N | N | N | N | N | R | R | ||
30 | ||||||||||||||||||||||||
31 | LEGEND | |||||||||||||||||||||||
32 | DAYS | D | ||||||||||||||||||||||
33 | NIGHTS | N | ||||||||||||||||||||||
34 | RNR | R | ||||||||||||||||||||||
35 | ANNUAL LEAVE | AL | ||||||||||||||||||||||
36 | TRAINING | TR | ||||||||||||||||||||||
37 | SICK LEAVE | SL | ||||||||||||||||||||||
38 | OFF SITE / SECONDMENTS | O | ||||||||||||||||||||||
39 | ||||||||||||||||||||||||
40 | Captain | |||||||||||||||||||||||
41 | Medic | |||||||||||||||||||||||
42 | Trained | |||||||||||||||||||||||
43 | Lv1 Only | |||||||||||||||||||||||
44 | Recruit | |||||||||||||||||||||||
45 | ||||||||||||||||||||||||
2024 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D1:V1 | D1 | =COUNTIFS(D$10:D$41,"D",$C$10:$C$41,"Captain")+COUNTIFS(D$10:D$41,"D",$C$10:$C$41,"Medic")+COUNTIFS(D$10:D$41,"D",$C$10:$C$41,"Trained") |
D2:V2 | D2 | =COUNTIFS(D$10:D$41,"D",$C$10:$C$41,"Lv1 Only")+COUNTIFS(D$10:D$41,"D",$C$10:$C$41,"Recruit") |
D4:V4 | D4 | =COUNTIFS(D$10:D$41,"N",$C$10:$C$41,"Captain")+COUNTIFS(D$10:D$41,"N",$C$10:$C$41,"Medic")+COUNTIFS(D$10:D$41,"N",$C$10:$C$41,"Trained") |
D5:V5 | D5 | =COUNTIFS(D$10:D$41,"N",$C$10:$C$41,"Lv1 Only")+COUNTIFS(D$10:D$41,"N",$C$10:$C$41,"Recruit") |
D8:V8 | D8 | =WEEKDAY(D9) |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
C3:C4,D1:V5 | Cell | contains a blank value | text | YES |
C3:C4,D1:V5 | Cell Value | between 5 and 50 | text | NO |
C3:C4,D1:V5 | Cell Value | between 3 and 4 | text | NO |
C3:C4,D1:V5 | Cell Value | <=3 | text | NO |
C6,D7:D8,E8:V8,C9:C1048576 | Cell Value | ="Captain" | text | NO |
C6,D7:D8,E8:V8,C9:C1048576 | Cell Value | ="Medic" | text | NO |
C6,D7:D8,E8:V8,C9:C1048576 | Cell Value | ="Trained" | text | NO |
C6,D7:D8,E8:V8,C9:C1048576 | Cell Value | ="Lv1 Only" | text | NO |
C6,D7:D8,E8:V8,C9:C1048576 | Cell Value | ="Recruit" | text | NO |
9:9 | Dates Occurring | today | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="TR" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="R" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="O" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="AL" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="SL" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="N" | text | NO |
A6:V6,A7,A3:B4,A1:A2,A4:A5,A32:V41,A31,C31:V31,D7:V8,A9:V30 | Cell Value | ="D" | text | NO |
B32:B41,B10:B30 | Expression | =$C10="Captain" | text | NO |
B32:B41,B10:B30 | Expression | =$C10="Medic" | text | NO |
B32:B41,B10:B30 | Expression | =$C10="Trained" | text | NO |
B32:B41,B10:B30 | Expression | =$C10="Lv1 Only" | text | NO |
B32:B41,B10:B30 | Expression | =$C10="Recruit" | text | NO |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
C10:C29 | List | =$A$40:$A$45 |
D10:V29 | List | D, N, AL, SL, TR, O, R |
VBA's
VBA Code:
Sub refresh_ERT7DayForecast()
UnhideRows
ResetPage
Clear_DS
Clear_NS
FullERT_DS
TraineeERT_DS
FullERT_NS
TraineeERT_NS
HideEmptyRows
Range("C2").Select
End Sub
Sub FullERT_DS()
'get user define start date from worksheet "ERT 7 Day Forecast"
StartDate = Sheets("ERT 7 Day Forecast").Range("C2").Value
'find date start col from worksheet "2024"
Startcol = 4
readrow = 9
readCol = Startcol
Do While Sheets("2024").Cells(readrow, readCol).Value <> StartDate
readCol = readCol + 1
Loop
Startcol = readCol
'Loop for 7 days
writecol = 2
Do While writecol < 9
writerow = 15
'Loop down for Captain
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Captain" Then
If Sheets("2024").Cells(readrow, readCol).Value = "D" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Captain"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Medic "Cert 4 qualified"
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Medic" Then
If Sheets("2024").Cells(readrow, readCol).Value = "D" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Medic"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Trained
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Trained" Then
If Sheets("2024").Cells(readrow, readCol).Value = "D" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Trained"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
readCol = readCol + 1
writecol = writecol + 1
Loop
End Sub
Sub TraineeERT_DS()
'get user define start date from worksheet "ERT 7 Day Forecast"
StartDate = Sheets("ERT 7 Day Forecast").Range("C2").Value
'find date start col from worksheet "2024"
Startcol = 4
readrow = 9
readCol = Startcol
Do While Sheets("2024").Cells(readrow, readCol).Value <> StartDate
readCol = readCol + 1
Loop
Startcol = readCol
'Loop for 7 days
writecol = 2
Do While writecol < 9
writerow = 30
'Loop down for Lv1 Only
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Lv1 Only" Then
If Sheets("2024").Cells(readrow, readCol).Value = "D" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Level 1"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Recruit
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Recruit" Then
If Sheets("2024").Cells(readrow, readCol).Value = "D" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Trainee"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
readCol = readCol + 1
writecol = writecol + 1
Loop
End Sub
Sub FullERT_NS()
Clear_NS
'get user define start date from worksheet "2024"
StartDate = Sheets("ERT 7 Day Forecast").Range("C2").Value
'find date start col from worksheet "2024"
Startcol = 4
readrow = 9
readCol = Startcol
Do While Sheets("2024").Cells(readrow, readCol).Value <> StartDate
readCol = readCol + 1
Loop
Startcol = readCol
'Loop for 7 days
writecol = 11
Do While writecol < 18
writerow = 15
'Loop down for Captain
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Captain" Then
If Sheets("2024").Cells(readrow, readCol).Value = "N" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Captain"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Medic "Cert 4 qualified"
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Medic" Then
If Sheets("2024").Cells(readrow, readCol).Value = "N" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Medic"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Trained
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Trained" Then
If Sheets("2024").Cells(readrow, readCol).Value = "N" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Trained"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
readCol = readCol + 1
writecol = writecol + 1
Loop
End Sub
Sub TraineeERT_NS()
'get user define start date from worksheet "2024"
StartDate = Sheets("ERT 7 Day Forecast").Range("C2").Value
'find date start col from worksheet "2024"
Startcol = 4
readrow = 9
readCol = Startcol
Do While Sheets("2024").Cells(readrow, readCol).Value <> StartDate
readCol = readCol + 1
Loop
Startcol = readCol
'Loop for 7 days
writecol = 11
Do While writecol < 18
writerow = 30
'Loop down for Lv1 Only
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Lv1 Only" Then
If Sheets("2024").Cells(readrow, readCol).Value = "N" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Level 1"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
'Loop down for Recruit
readrow = 10
Do While Sheets("2024").Cells(readrow, 3).Value <> ""
If Sheets("2024").Cells(readrow, 3).Value = "Recruit" Then
If Sheets("2024").Cells(readrow, readCol).Value = "N" Then
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Value = Sheets("2024").Cells(readrow, 2).Value
Sheets("ERT 7 Day Forecast").Cells(writerow, writecol).Style = "Trainee"
writerow = writerow + 1
End If
End If
readrow = readrow + 1
Loop
readCol = readCol + 1
writecol = writecol + 1
Loop
End Sub
Sub Clear_DS()
Sheets("ERT 7 Day Forecast").Select
Range("B15:H44").Select
Selection.ClearContents
Selection.Style = "Normal"
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
Sub Clear_NS()
Sheets("ERT 7 Day Forecast").Select
Range("K15:Q44").Select
Selection.ClearContents
Selection.Style = "Normal"
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
Sub HideEmptyRows()
Dim r As Range, rows As Long, i As Long
Set r = ActiveSheet.rows("15:44")
rows = r.rows.Count
For i = rows To 1 Step (-1)
If WorksheetFunction.CountA(r.rows(i)) = 0 Then r.rows(i).Hidden = True
Next
End Sub
Sub UnhideRows()
rows("15:50").Select
Selection.EntireRow.Hidden = False
Range("C2").Select
End Sub
Sub ResetPage()
Sheets("MASTER").Select
rows("9:60").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("ERT 7 Day Forecast").Select
rows("9").Select
ActiveSheet.Paste
Range("C2").Select
End Sub
Last edited by a moderator: