Sub noDays()
'Unportecting the sheet to make changes to the cells
ActiveWorkbook.Worksheets("Host Txbl Wages").Unprotect
ActiveWorkbook.Worksheets("Home Txbl Wages").Unprotect
ActiveWorkbook.Worksheets("Home Hypo Wages").Unprotect
'Screen updating would not take place rather we would see a rolling circle
Application.ScreenUpdating = False
'i is set as the column start
i = 4
'was used for the off set cell calculation in tax calculation
j = 0
'calls the function which clears the borders
Call clearBorder
'calls the function which clears the data filled in the tables due to excel formulae calculation with out deleting the actual formulae
Call DaysClear
'gets the Assignment start date
stDate = ActiveWorkbook.Worksheets("Input Section").Range("E15").Value
'gets the Assignment end date
enDate = ActiveWorkbook.Worksheets("Input Section").Range("E16").Value
'checks if the endate was given less than the start date
If enDate < stDate Then
MsgBox "End date cannot be less than Start date!!"
Exit Sub
End If
'total no.of year of assignment
yrdiff = Year(enDate) - Year(stDate)
'if the assignment finishes with in one year, we would just display the start date and endate
If yrdiff = 0 Then
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(122, i).Value = stDate
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(122, i).Value = stDate
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(122, i).Value = stDate
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(123, i).Value = enDate
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(123, i).Value = enDate
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(123, i).Value = enDate
'display the calendar year
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(126, i).Value = Year(enDate)
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(126, i).Value = Year(enDate)
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(126, i).Value = Year(enDate)
'Bordering for the data which was displayed
Sheets("Host Txbl Wages").Activate
Range("D122:D155").Select
Call bordering
'if the assignment lasts for more than a year
Else
' set the first date of the table as assignment start date
hostStartYear = stDate
'set the end of the calendar year
hostEndYear = DateSerial(Year(hostStartYear), 12, 31)
'comes out of the loop once the hostEndYear becomes greater than the assignment end date
While enDate > hostEndYear
'enDate would always be greater than hostEndYear if not the first condtion would make it work
If enDate > hostEndYear Then
'set the first cell
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(122, i).Value = hostStartYear
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(122, i).Value = hostStartYear
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(122, i).Value = hostStartYear
'the next cell as the host end year
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(123, i).Value = DateSerial(Year(hostStartYear), 12, 31)
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(123, i).Value = DateSerial(Year(hostStartYear), 12, 31)
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(123, i).Value = DateSerial(Year(hostStartYear), 12, 31)
'display the calendar year
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(126, i).Value = Year(hostEndYear)
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(126, i).Value = Year(hostEndYear)
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(126, i).Value = Year(hostEndYear)
'set the hostStart a year more for the next iteration
hostStartYear = DateSerial(Year(hostEndYear) + 1, 1, 1)
'sets the end year of the hostStartYear
hostEndYear = DateSerial(Year(hostStartYear), 12, 31)
End If
'increment the column
i = i + 1
'increments the column value in wages/allowances
j = j + 1
'ends while when the hostEndYear becomes more than the assignment endDate and then display the start of the year and the end Date
Wend
'the first cell in the last column
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(122, i).Value = hostStartYear
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(122, i).Value = hostStartYear
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(122, i).Value = hostStartYear
'the last cell in the range of the last column
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(123, i).Value = enDate
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(123, i).Value = enDate
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(123, i).Value = enDate
'display the calendar year
ActiveWorkbook.Worksheets("Host Txbl Wages").Cells(126, i).Value = Year(enDate)
ActiveWorkbook.Worksheets("Home Txbl Wages").Cells(126, i).Value = Year(enDate)
ActiveWorkbook.Worksheets("Home Hypo Wages").Cells(126, i).Value = Year(enDate)
'Borders the table
Call tableDays
'ends the initial condtion of the assignment duration of one or more years
End If
'Font size and alignment
'Activates the the sheet where we need the font alignment
Call align
'calls the second table
Call daysInFiscal
'proceeds to convert in to Fiscal year
Call hostYearConversion
'calls the last Fiscal to Calendar Conversion
Call FiscalToCalendar
ActiveWorkbook.Worksheets("Host Txbl Wages").Range("$A$4:$A$114").AutoFilter Field:=1, Criteria1:="1"
'End of the funtion
End Sub
Bookmarks