EVO Payroll Finance Report with auto save year and month wise
EVO Payroll Finance Report with auto save year and month wise
Application.ScreenUpdating = False
PayrollFile = Application.GetOpenFilename(Title:="Browse for your Payroll
File", fileFilter:="Excel Files (*.xls*),*xls*")
Select Case TypeName(PayrollFile)
Case "Boolean": MsgBox "No file selected. Exiting macro.": Exit Sub
Case Else
If PayrollFile = False Then MsgBox "File selection canceled. Exiting
macro.": Exit Sub
End Select
fileName = Mid(PayrollFile, InStrRev(PayrollFile, "\") + 1)
eFilename = Split(fileName, ".")(0)
Path = Left(PayrollFile, InStrRev(PayrollFile, "\"))
Workbooks.Open PayrollFile
Set Psheet = ActiveSheet
For i = 2 To lastRow
projects = Split(Psheet.Cells(i, colIndex).Value, "/")
For Each project In projects
If Not projectDict.exists(project) Then
projectDict.Add project, True
Psheet.Cells(1, Psheet.Columns.Count).End(xlToLeft).Offset(0,
1).Value = project
End If
Next project
Next i
For i = 2 To lastRow
If IsNumeric(Psheet.Cells(i, netSalaryCol).Value) And Psheet.Cells(i,
5).Value <> 0 Then
projects = Split(Psheet.Cells(i, colIndex).Value, "/")
costPerProject = Psheet.Cells(i, netSalaryCol).Value /
(UBound(projects) + 1)
For Each project In projects
For j = netSalaryCol To Psheet.Cells(1,
Psheet.Columns.Count).End(xlToLeft).Column
If Psheet.Cells(1, j).Value = project Then
Psheet.Cells(i, j).Value = costPerProject
End If
Next j
Next project
End If
Next i
' Find the "Name" column, go to the bottom of the data, offset by one row, and
delete that row
Set nameCol = Psheet.Rows(1).Find("Name", LookIn:=xlValues, LookAt:=xlWhole)
If Not nameCol Is Nothing Then
lastRow = Psheet.Cells(Psheet.Rows.Count, nameCol.Column).End(xlUp).Row
Psheet.Rows(lastRow + 1).Delete
End If
' Create folders and save the file using extracted year and month
yearFolder = fileYear
monthName = fileMonth ' Use the full month name extracted from the file name
savePath = Path & "Finance Reports\" & yearFolder & "\" & monthName & "\"
Application.ScreenUpdating = True
End Sub