Option Explicit
Public boolCancel As Boolean
Public strYear As String
Public strMonth As String
Public dtMonthEnd As Date
Public dtPriorMonthEnd As Date
Public strPriorYear As String
Public intMonth As Integer
Public intMonthOffset As Integer
Public intPriorMonth As Integer
Sub LBoSPAReturn()
Dim wbHRISDataFile As Workbook
Dim wbPAReturnFile As Workbook
Dim rngHRISDataStart As Range
Dim rngHRISDataAll As Range
Dim rngHRISDataReturnStart As Range
Dim rngHRISDataReturnAll As Range
Dim rngHRISDataReturn As Range
Dim rngHRISDataErrorCount As Range
Dim rngHRISDataAreaErrorCount As Range
Dim rngAreaListSendArea As Range
Dim rngBudgetsData As Range
Dim strBrand As String
Dim strChannel As String
Dim strNetwork As String
Dim strRegion As String
Dim strLDG As String
Dim currBudgetMonth1 As Currency
Dim currBudgetMonth2 As Currency
Dim currBudgetMonth3 As Currency
Dim currBudgetMonth4 As Currency
Dim currBudgetMonth5 As Currency
Dim currBudgetMonth6 As Currency
Dim currBudgetMonth7 As Currency
Dim currBudgetMonth8 As Currency
Dim currBudgetMonth9 As Currency
Dim currBudgetMonth10 As Currency
Dim currBudgetMonth11 As Currency
Dim currBudgetMonth12 As Currency
Dim rngHRISDataEmpRef As Range
Dim rngHRISDataBrand As Range
Dim rngHRISDataChannel As Range
Dim rngHRISDataNetwork As Range
Dim rngHRISDataRegion As Range
Dim rngHRISDataLDG As Range
Dim strTest As String
Dim rngDataBudget As Range
Dim rngPAHRISDataReturnStart As Range
Dim intCount As Integer
Dim rngAreaMoveDataStart As Range
Dim rngAreaMoveSummaryDataStart As Range
Dim rngStaffRefEmpRef As Range
Dim rngStaffRefBrand As Range
Dim rngStaffRefChannel As Range
Dim rngStaffRefNetwork As Range
Dim rngStaffRefRegion As Range
Dim rngStaffRefLDG As Range
Dim strPriorFile As String
Dim objPriorPeriodFile As Object
Dim boolPriorPeriodFile As Boolean
Dim wbPriorFile As Workbook
Dim intRowCount As Integer
Dim objFolder As Object
Dim strFolder As String
Dim boolPriorPeriodInflow As Boolean
Dim boolPriorPeriodAreaMove As Boolean
'trying to add the variable here
frmSelectDetails.Show
If boolCancel = True Then
MsgBox ("The process has been cancelled."), vbInformation
Exit Sub
Else
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Selection = "hello"
Sheets("HRIS Data for Return").Select
Set rngHRISDataErrorCount = Range("HRISData_ErrorCount") 'cleared
If WorksheetFunction.Sum(rngHRISDataErrorCount) > 0 Then
MsgBox ("There are 'Cost Codes' on the HRIS download that are not on the 'Structure' sheet." & vbCr & vbCr & _
"Check column AG on the 'HRIS Data' sheet and ensure the data on the 'Structure' sheet is up to date." & vbCr & vbCr & _
"No data has been sent to the Area PA's and this process will now end."), vbCritical
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Set rngHRISDataErrorCount = Nothing
Set rngHRISDataReturnStart = Nothing
Exit Sub
Else
End If
Set rngHRISDataErrorCount = Nothing
Set rngHRISDataAreaErrorCount = Range("HRISData_AreaErrorCount") 'cleared
If rngHRISDataAreaErrorCount > 0 Then
MsgBox ("There are areas on the HRIS data with no relevant PA.." & vbCr & vbCr & _
"Check column AL on the 'HRIS Data' sheet and ensure the 'PA List' sheet is up to date." & vbCr & vbCr & _
"No data has been sent to the Area PA's and this process will now end."), vbCritical
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Set rngHRISDataAreaErrorCount = Nothing
Set rngHRISDataReturnStart = Nothing
Exit Sub
Else
End If
Set rngHRISDataAreaErrorCount = Nothing
Set wbHRISDataFile = ActiveWorkbook 'cleared
Set rngHRISDataStart = Range("HRISData_DataStart") 'cleared
Set rngAreaListSendArea = Range("AreaList_SendStart") 'cleared
Set rngHRISDataEmpRef = Range(rngHRISDataStart, rngHRISDataStart.Offset(0, -8).End(xlDown).Offset(0, 8))
Set rngHRISDataBrand = rngHRISDataEmpRef.Offset(0, 3) 'cleared
Set rngHRISDataChannel = rngHRISDataEmpRef.Offset(0, 4) 'cleared
Set rngHRISDataNetwork = rngHRISDataEmpRef.Offset(0, 5) 'cleared
Set rngHRISDataRegion = rngHRISDataEmpRef.Offset(0, 6) 'cleared
Set rngHRISDataLDG = rngHRISDataEmpRef.Offset(0, 7) 'cleared
Set rngHRISDataAll = Range(rngHRISDataEmpRef, rngHRISDataLDG.Offset(0, 2)) 'cleared
Do Until rngAreaListSendArea = ""
If rngAreaListSendArea = "No" Then
Else
Set rngHRISDataReturnStart = Range("HRISDataReturn_DataStart").Offset(1, 0) 'cleared
Range(rngHRISDataReturnStart, rngHRISDataReturnStart.End(xlDown).End(xlToRight)).Select
Selection.ClearContents
strBrand = rngAreaListSendArea.Offset(0, -6)
strChannel = rngAreaListSendArea.Offset(0, -5)
strNetwork = rngAreaListSendArea.Offset(0, -4)
strRegion = rngAreaListSendArea.Offset(0, -3)
strLDG = rngAreaListSendArea.Offset(0, -2)
strFolder = "C:\Documents and Settings\423457\" & "Desktop\Work in Progress - Tansfer to Network\LBoS PA Return\Current Month Returns\" & strBrand
Set objFolder = CreateObject("Scripting.FileSystemObject") 'cleared
If objFolder.FolderExists(strFolder) Then
strFolder = strFolder & "\" & strChannel
If objFolder.FolderExists(strFolder) Then
strFolder = strFolder & "\" & strNetwork
If objFolder.FolderExists(strFolder) Then
strFolder = strFolder & "\" & strRegion
If objFolder.FolderExists(strFolder) Then
Else
objFolder.createfolder (strFolder)
End If
Else
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strRegion
objFolder.createfolder (strFolder)
End If
Else
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strNetwork
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strRegion
objFolder.createfolder (strFolder)
End If
Else
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strChannel
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strNetwork
objFolder.createfolder (strFolder)
strFolder = strFolder & "\" & strRegion
objFolder.createfolder (strFolder)
End If
Set objFolder = Nothing
Set rngBudgetsData = Range("Budgets_DataStart") 'cleared
Do Until rngBudgetsData = strBrand And rngBudgetsData.Offset(0, 1) = strChannel And rngBudgetsData.Offset(0, 3) = strRegion And rngBudgetsData.Offset(0, 3) = strRegion And rngBudgetsData.Offset(0, 4) = strLDG
Set rngBudgetsData = rngBudgetsData.Offset(1, 0)
Loop
currBudgetMonth1 = rngBudgetsData.Offset(0, 6 + intMonthOffset)
currBudgetMonth2 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 1)
currBudgetMonth3 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 2)
currBudgetMonth4 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 3)
currBudgetMonth5 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 4)
currBudgetMonth6 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 5)
currBudgetMonth7 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 6)
currBudgetMonth8 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 7)
currBudgetMonth9 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 8)
currBudgetMonth10 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 9)
currBudgetMonth11 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 10)
currBudgetMonth12 = rngBudgetsData.Offset(0, 6 + intMonthOffset + 11)
Set rngBudgetsData = Nothing
rngHRISDataAll.Copy
rngHRISDataReturnStart.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set rngHRISDataReturnAll = Range(rngHRISDataReturnStart, rngHRISDataReturnStart.End(xlDown).Offset(0, 9)) 'cleared
rngHRISDataReturnAll.Sort Key1:=Range("D7"), Order1:=xlAscending, Key2:=Range("E7") _
, Order2:=xlAscending, Key3:=Range("G7"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
Set rngHRISDataReturnAll = Nothing
Set rngHRISDataReturn = rngHRISDataReturnStart 'cleared
Do Until rngHRISDataReturn = ""
If rngHRISDataReturn.Offset(0, 3) = strBrand And rngHRISDataReturn.Offset(0, 4) = strChannel And rngHRISDataReturn.Offset(0, 6) = strRegion Then
Do Until rngHRISDataReturn.Offset(0, 3) <> strBrand Or rngHRISDataReturn.Offset(0, 4) <> strChannel Or rngHRISDataReturn.Offset(0, 6) <> strRegion
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
Else
Do Until rngHRISDataReturn.Offset(0, 3) = strBrand And rngHRISDataReturn.Offset(0, 4) = strChannel And rngHRISDataReturn.Offset(0, 6) = strRegion
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
Set rngHRISDataReturnStart = rngHRISDataReturn
Range(rngHRISDataReturn.Offset(-1, 0), rngHRISDataReturn.End(xlUp).Offset(1, 0).EntireRow).Select
Selection.Delete
Do Until rngHRISDataReturn.Offset(0, 3) <> strBrand Or rngHRISDataReturn.Offset(0, 4) <> strChannel Or rngHRISDataReturn.Offset(0, 6) <> strRegion
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
End If
If rngHRISDataReturn = "" Then
Else
Range(rngHRISDataReturn, rngHRISDataReturn.End(xlDown).EntireRow).Select
Selection.Delete
Set rngHRISDataReturn = ActiveCell
End If
Loop
Set rngHRISDataReturnAll = Range(rngHRISDataReturnStart, rngHRISDataReturnStart.End(xlDown).Offset(0, 9))
rngHRISDataReturnAll.Sort Key1:=Range("H7"), Order1:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
Set rngHRISDataReturn = rngHRISDataReturnStart
Do Until rngHRISDataReturn = ""
If rngHRISDataReturn.Offset(0, 7) = strLDG Then
Do Until rngHRISDataReturn.Offset(0, 7) <> strLDG
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
Else
Do Until rngHRISDataReturn.Offset(0, 7) = strLDG
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
Set rngHRISDataReturnStart = rngHRISDataReturn
Range(rngHRISDataReturn.Offset(-1, 0), rngHRISDataReturn.End(xlUp).Offset(1, 0).EntireRow).Select
Selection.Delete
Do Until rngHRISDataReturn.Offset(0, 7) <> strLDG
Set rngHRISDataReturn = rngHRISDataReturn.Offset(1, 0)
Loop
If rngHRISDataReturn = "" Then
Else
Range(rngHRISDataReturn, rngHRISDataReturn.End(xlDown).EntireRow).Select
Selection.Delete
Set rngHRISDataReturn = ActiveCell
End If
End If
Loop
Set wbPAReturnFile = Workbooks.Open("C:\Documents and Settings\423457\Desktop\Work in Progress - Tansfer to Network\LBoS PA Return\LBoS PA Update File.xls")
Range("Today") = dtMonthEnd
Range("Brand") = strBrand
Range("Channel") = strChannel
Range("Network") = strNetwork
Range("Region") = strRegion
Range("LDG") = strLDG
Set rngDataBudget = Range("BudgetJanCurrYear") 'cleared
rngDataBudget.Offset(intMonth, 0) = currBudgetMonth1
rngDataBudget.Offset(intMonth + 1, 0) = currBudgetMonth2
rngDataBudget.Offset(intMonth + 2, 0) = currBudgetMonth3
rngDataBudget.Offset(intMonth + 3, 0) = currBudgetMonth4
rngDataBudget.Offset(intMonth + 4, 0) = currBudgetMonth5
rngDataBudget.Offset(intMonth + 5, 0) = currBudgetMonth6
rngDataBudget.Offset(intMonth + 6, 0) = currBudgetMonth7
rngDataBudget.Offset(intMonth + 7, 0) = currBudgetMonth8
rngDataBudget.Offset(intMonth + 8, 0) = currBudgetMonth9
rngDataBudget.Offset(intMonth + 9, 0) = currBudgetMonth10
rngDataBudget.Offset(intMonth + 10, 0) = currBudgetMonth11
rngDataBudget.Offset(intMonth + 11, 0) = currBudgetMonth12
Set rngDataBudget = Nothing
Set rngStaffRefEmpRef = Range("StaffRef_EmpRefStart") 'cleared
Set rngStaffRefBrand = Range("StaffRef_BrandStart") 'cleared
Set rngStaffRefChannel = Range("StaffRef_ChannelStart") 'cleared
Set rngStaffRefNetwork = Range("StaffRef_NetworkStart") 'cleared
Set rngStaffRefRegion = Range("StaffRef_RegionStart") 'cleared
Set rngStaffRefLDG = Range("StaffRef_LDGStart") 'cleared
rngHRISDataEmpRef.Copy
rngStaffRefEmpRef.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngHRISDataBrand.Copy
rngStaffRefBrand.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngHRISDataChannel.Copy
rngStaffRefChannel.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngHRISDataNetwork.Copy
rngStaffRefNetwork.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngHRISDataRegion.Copy
rngStaffRefRegion.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
rngHRISDataLDG.Copy
rngStaffRefLDG.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set rngPAHRISDataReturnStart = Range("HRISData_DataStart") 'cleared
rngHRISDataReturnAll.Copy
rngPAHRISDataReturnStart.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Set rngHRISDataReturnAll = Nothing
Set rngPAHRISDataReturnStart = Nothing
Set rngStaffRefEmpRef = Nothing
Set rngStaffRefBrand = Nothing
Set rngStaffRefChannel = Nothing
Set rngStaffRefNetwork = Nothing
Set rngStaffRefRegion = Nothing
Set rngStaffRefLDG = Nothing
intCount = Range("HRISData_Count")
Sheets("Area Movement").Select
Set rngAreaMoveDataStart = Range("AreaMovement_DataStart")
Range(rngAreaMoveDataStart.Offset(intCount, 0), rngAreaMoveDataStart.End(xlDown).EntireRow).Delete
Set rngAreaMoveDataStart = Nothing
Sheets("Area Movement Summary").Select
Set rngAreaMoveSummaryDataStart = Range("AreaMovementSummary_DataStart")
Range(rngAreaMoveSummaryDataStart.Offset(intCount, 0), rngAreaMoveSummaryDataStart.End(xlDown).EntireRow).Delete
Set rngAreaMoveSummaryDataStart = Nothing
strPriorFile = "C:\Documents and Settings\423457\" & "Desktop\Work in Progress - Tansfer to Network\LBoS PA Return\Prior Month Returns\" & strBrand & "\" & strChannel & "\" & _
strNetwork & "\" & strRegion & "\" & Replace(strLDG, " & ", " ") & " " & Format(dtPriorMonthEnd, "mmm yy") & ".xls"
Set objPriorPeriodFile = CreateObject("Scripting.FileSystemObject") 'cleared
If Not objPriorPeriodFile.FileExists(strPriorFile) Then
boolPriorPeriodFile = False
Else
boolPriorPeriodFile = True
End If
Set objPriorPeriodFile = Nothing
If boolPriorPeriodFile = True Then
Set wbPriorFile = Workbooks.Open(strPriorFile, UpdateLinks:=0) 'cleared
wbPriorFile.Sheets("Inflow").Activate
Range("Inflow_DataStart").Select
intRowCount = 0
If Selection.Offset(0, 1) = "" Then
boolPriorPeriodInflow = False
Else
boolPriorPeriodInflow = True
Do Until Selection.Offset(intRowCount, 1) = ""
intRowCount = intRowCount + 1
Loop
Range(Selection, Selection.Offset(intRowCount - 1, 7)).Copy
wbPAReturnFile.Sheets("Previous Inflow").Activate
Range("A11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
wbPriorFile.Sheets("Area Movement Summary").Activate
Range("A10").Select
intRowCount = 0
If Selection = "" Then
boolPriorPeriodAreaMove = False
Else
boolPriorPeriodAreaMove = True
Do Until Selection.Offset(intRowCount, 0) = ""
intRowCount = intRowCount + 1
Loop
Range(Selection, Selection.Offset(intRowCount - 1, 10)).Copy
wbPAReturnFile.Sheets("Previous Area Movements").Activate
Range("A11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Application.CutCopyMode = False
wbPriorFile.Close savechanges:=False
Set wbPriorFile = Nothing
Else
End If
Sheets("HRIS Data").Visible = xlVeryHidden
Sheets("Previous Area Movements").Visible = xlVeryHidden
Sheets("Previous Inflow").Visible = xlVeryHidden
Sheets("Lookups").Visible = xlVeryHidden
Sheets("Staff Ref").Visible = xlVeryHidden
Sheets("Data").Visible = xlVeryHidden
Sheets("Summary").Activate
wbPAReturnFile.SaveAs "C:\Documents and Settings\423457\" & "Desktop\Work in Progress - Tansfer to Network\LBoS PA Return\Current Month Returns\" & strBrand & "\" & strChannel & "\" & strNetwork & "\" & strRegion & "\" & Replace(strLDG, " & ", " ") & " " & Format(dtMonthEnd, "mmm yy") & ".xls"
wbPAReturnFile.Close
Set wbPAReturnFile = Nothing
End If
Set rngAreaListSendArea = rngAreaListSendArea.Offset(1, 0)
Set rngHRISDataReturn = Nothing
Set rngHRISDataReturnStart = Nothing
Loop
Set rngHRISDataEmpRef = Nothing
Set rngHRISDataBrand = Nothing
Set rngHRISDataChannel = Nothing
Set rngHRISDataNetwork = Nothing
Set rngHRISDataRegion = Nothing
Set rngHRISDataLDG = Nothing
Set rngHRISDataAll = Nothing
Set rngHRISDataStart = Nothing
Set rngAreaListSendArea = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Set wbHRISDataFile = Nothing
End Sub