This is the first Call
Private Sub CreateNamedWorkbook()
'On Error GoTo ErrorHandler
Dim strPath As String
Dim adacSheetCount, I As Integer
strPath = **removed directory**
GLB_workname = ActiveWorkbook.Name
GLB_filename = GLB_facility & " - Staff Record of Learning " & Day(Date) & "-" & Month(Date) & "-" & Year(Date)
Workbooks.Add.SaveAs Filename:=(strPath & GLB_filename), FileFormat:=51
GLB_filename = GLB_filename & ".xlsx"
Workbooks(GLB_filename).Sheets("Sheet2").Delete
Workbooks(GLB_filename).Sheets("Sheet3").Delete
adacSheetCount = Workbooks(GLB_workname).Sheets.Count
' I = 9
For I = 1 To adacSheetCount
If Workbooks(GLB_workname).Sheets(I).Name <> "CPP Movements" And Workbooks(GLB_workname).Sheets(I).Name <> "REPORTS" Then
Workbooks(GLB_filename).Sheets.Add After:=Sheets(Sheets.Count)
GLB_currentSheet = Workbooks(GLB_workname).Sheets(I).Name
Workbooks(GLB_filename).Sheets(Sheets.Count).Name = GLB_currentSheet
Workbooks(GLB_workname).Sheets(I).Activate
Call MoveInfoTemp
Call SheetHeaderSetup
Call MoveInfoFinal
End If
Next
Workbooks(GLB_filename).Sheets("Sheet1").Delete
Workbooks(GLB_filename).Save
Workbooks(GLB_filename).Close
Workbooks(GLB_workname).Sheets("REPORTS").Activate
'Exit Sub
'ErrorHandler:
' MsgBox "CreateNamedWorkbook"
' Resume Next
End Sub
Then this runs
Private Sub MoveInfoTemp()
On Error GoTo ErrorHandler
Dim facColNum, lastRow, lastCol, firstCol, firstRow, I As Integer
Dim toCopy As Range
Range("A1").Select
Cells.Find(What:="Employee #", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Select
firstRow = ActiveCell.Row
lastCol = Cells(firstRow, 100).End(xlToLeft).Column
Cells(firstRow, 1).Select
lastRow = Range("A65536").End(xlUp).Row
facColNum = Application.WorksheetFunction.Match("Facility", Range(firstRow & ":" & firstRow), 0)
ActiveSheet.Range(Cells(firstRow, 1), Cells(lastRow, lastCol)).AutoFilter Field:=facColNum, Criteria1:=GLB_facility
Set toCopy = ActiveSheet.Range("A" & firstRow & ":A" & lastRow)
For I = 2 To lastCol
If Cells(firstRow, I).Interior.ColorIndex = 55 Then
Set toCopy = Union(toCopy, ActiveSheet.Range(Cells(firstRow, I), Cells(lastRow, I)))
End If
Next
toCopy.Copy
Workbooks(GLB_filename).Sheets("Sheet1").Paste
GLB_colNum = Workbooks(GLB_filename).Sheets("Sheet1").Cells(1, 100).End(xlToLeft).Column
ActiveSheet.Range(Cells(firstRow, 1), Cells(lastRow, lastCol)).AutoFilter
Exit Sub
ErrorHandler:
MsgBox "MoveInfoTemp"
' Resume Next
End Sub
Then this:
Private Sub SheetHeaderSetup()
On Error GoTo ErrorHandler
Dim procYear, I, dateColNum As Integer
Dim maxDate, minDate, dateColLet As Date
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A1").Value = GLB_facility
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A1").Interior
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
End With
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A1").Font
.Name = "Arial"
.Size = 24
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0.399975585192419
End With
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Activate
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(1, 1), Cells(1, GLB_colNum))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(1, 1), Cells(1, GLB_colNum)).Merge
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A2").Value = Workbooks(GLB_workname).Sheets(GLB_currentSheet).Range("A1").Value
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A2").Interior
.ThemeColor = xlThemeColorLight2
.TintAndShade = 0
End With
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A2").Font
.Name = "Arial"
.Size = 14
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(2, 1), Cells(2, GLB_colNum))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(2, 1), Cells(2, GLB_colNum)).Merge
Workbooks(GLB_filename).Sheets("Sheet1").Activate
dateColNum = Application.WorksheetFunction.Match("Date", Range("1:1"), 0)
maxDate = Application.WorksheetFunction.Max(Range(Cells(1, dateColNum), Cells(100000, dateColNum)))
minDate = Application.WorksheetFunction.Min(Range(Cells(1, dateColNum), Cells(100000, dateColNum)))
procYear = Year(minDate)
GLB_yearNum = 3
If minDate <> 0 Then
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Activate
Do While procYear - 1 <> Year(maxDate)
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A" & GLB_yearNum).Value = procYear & " Staff Totals"
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A" & GLB_yearNum).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A" & GLB_yearNum).Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("A" & GLB_yearNum).Font.Bold = True
Workbooks(GLB_filename).Sheets("Sheet1").Activate
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range("B" & GLB_yearNum).Value = (Application.WorksheetFunction.CountIf(Workbooks(GLB_filename).Sheets("Sheet1").Range(Cells(1, dateColNum), Cells(100000, dateColNum)), "<" & DateSerial(procYear + 1, 1, 1)) - Application.WorksheetFunction.CountIf(Workbooks(GLB_filename).Sheets("Sheet1").Range(Cells(1, dateColNum), Cells(100000, dateColNum)), "<" & DateSerial(procYear, 1, 1)))
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Activate
With Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(GLB_yearNum, 2), Cells(GLB_yearNum, GLB_colNum))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Range(Cells(GLB_yearNum, 2), Cells(GLB_yearNum, GLB_colNum)).Merge
GLB_yearNum = GLB_yearNum + 1
procYear = procYear + 1
Loop
End If
Exit Sub
ErrorHandler:
MsgBox "SheetHeaderSetup"
' Resume Next
End Sub
And finally:
Private Sub MoveInfoFinal()
On Error GoTo ErrorHandler
Dim lastRow, lastCol As Integer
Workbooks(GLB_filename).Sheets("Sheet1").Activate
lastRow = Range("A65536").End(xlUp).Row
Range(Cells(1, 1), Cells(lastRow, GLB_colNum)).Copy
Workbooks(GLB_filename).Sheets(GLB_currentSheet).Activate
Range("A" & GLB_yearNum).Select
ActiveSheet.Paste
ActiveCell.Columns("A:" & ColLett(GLB_colNum)).EntireColumn.EntireColumn.AutoFit
Workbooks(GLB_filename).Sheets("Sheet1").Delete
Workbooks(GLB_filename).Sheets.Add Before:=Sheets(1)
Workbooks(GLB_filename).Sheets(1).Name = "Sheet1"
Exit Sub
ErrorHandler:
MsgBox "MoveInfoFinal"
' Resume Next
End Sub
Bookmarks