Hello All,
I've got the below code which is working fine but currently is not very efficient. Wondering if anyone knows how I can change this so that it's using arrays? From reading the forum it seems if I use arrays this will be much faster. I have 6 other similar codes to below doing exactly the same thing but looking at different tables in the workbook and going through 80,000 lines. In total it's taking about 20 mins to run!
The aim is to calculate salary increases for employees who are eligible based on various recomended percentages e.g industry views/recruiter views/experts views etc. Below is the example calculating using industry recomended percentages.
Thanks!
Option Explicit</SPAN>
Public Function Salary_Increase()</SPAN>
Dim Ln As Long, x As Long, </SPAN>
Dim Industry_Forecast_Tbl As Variant, Data_Tbl As Variant, Increase_Type_Tbl As Variant</SPAN>
Dim CY_Salary As Variant, PT_Perc As Variant, Staff_Id As Variant, Eligibility_Input As Variant</SPAN>
Dim Scenario_2_Percent As Variant, Scenario_2_FTE As Variant, Scenario_2_Actual As Variant</SPAN>
Industry_Forecast_Tbl = Range("Inflation_Tbl")</SPAN>
Data_Tbl = Range("Data_Tbl")</SPAN>
CY_Salary = Range("Data_Tbl[CY FTE Salary GBP]")</SPAN>
PT_Perc = Range("Data_Tbl[CY Part-Time Percent]")</SPAN>
Staff_Id = Range("Data_Tbl[Staff ID]")</SPAN>
Eligibility_Input = Range("Data_Tbl[Salary Increment Eligibility]")</SPAN>
ReDim Scenario_2_FTE(1 To UBound(Staff_Id), 1 To 1)</SPAN>
ReDim Scenario_2_Actual(1 To UBound(Staff_Id), 1 To 1)</SPAN>
ReDim Scenario_2_Percent(1 To UBound(Staff_Id), 1 To 1)</SPAN>
For Ln = 1 To UBound(Staff_Id)</SPAN>
For x = 1 To UBound(Inflation_Country)</SPAN>
If Eligibility_Input(Ln, 1) = "Eligible" Then</SPAN>
If Data_Tbl(Ln, 14) = Industry_Forecast_Tbl (x, 1) Then</SPAN>
Scenario_2_Percent(Ln, 1) = Industry_Forecast_Tbl (x, 2)</SPAN>
Scenario_2_FTE(Ln, 1) = Industry_Forecast_Tbl (x, 2) * CY_Salary(Ln, 1)</SPAN>
Scenario_2_Actual(Ln, 1) = Industry_Forecast_Tbl (x, 2) * CY_Salary(Ln, 1) * PT_Perc(Ln, 1)</SPAN>
End If</SPAN>
End If</SPAN>
Next x</SPAN>
Next Ln</SPAN>
Range("Data_Tbl[Scenario 2 - Increase %]") = Scenario_2_Percent</SPAN>
Range("Data_Tbl[Scenario 2 -FTE Increase GBP]") = Scenario_2_FTE</SPAN>
Range("Data_Tbl[Scenario 2 -Actual Increase GBP]") = Scenario_2_Actual</SPAN>
End Function</SPAN>
I've got the below code which is working fine but currently is not very efficient. Wondering if anyone knows how I can change this so that it's using arrays? From reading the forum it seems if I use arrays this will be much faster. I have 6 other similar codes to below doing exactly the same thing but looking at different tables in the workbook and going through 80,000 lines. In total it's taking about 20 mins to run!
The aim is to calculate salary increases for employees who are eligible based on various recomended percentages e.g industry views/recruiter views/experts views etc. Below is the example calculating using industry recomended percentages.
Thanks!
Option Explicit</SPAN>
Public Function Salary_Increase()</SPAN>
Dim Ln As Long, x As Long, </SPAN>
Dim Industry_Forecast_Tbl As Variant, Data_Tbl As Variant, Increase_Type_Tbl As Variant</SPAN>
Dim CY_Salary As Variant, PT_Perc As Variant, Staff_Id As Variant, Eligibility_Input As Variant</SPAN>
Dim Scenario_2_Percent As Variant, Scenario_2_FTE As Variant, Scenario_2_Actual As Variant</SPAN>
Industry_Forecast_Tbl = Range("Inflation_Tbl")</SPAN>
Data_Tbl = Range("Data_Tbl")</SPAN>
CY_Salary = Range("Data_Tbl[CY FTE Salary GBP]")</SPAN>
PT_Perc = Range("Data_Tbl[CY Part-Time Percent]")</SPAN>
Staff_Id = Range("Data_Tbl[Staff ID]")</SPAN>
Eligibility_Input = Range("Data_Tbl[Salary Increment Eligibility]")</SPAN>
ReDim Scenario_2_FTE(1 To UBound(Staff_Id), 1 To 1)</SPAN>
ReDim Scenario_2_Actual(1 To UBound(Staff_Id), 1 To 1)</SPAN>
ReDim Scenario_2_Percent(1 To UBound(Staff_Id), 1 To 1)</SPAN>
For Ln = 1 To UBound(Staff_Id)</SPAN>
For x = 1 To UBound(Inflation_Country)</SPAN>
If Eligibility_Input(Ln, 1) = "Eligible" Then</SPAN>
If Data_Tbl(Ln, 14) = Industry_Forecast_Tbl (x, 1) Then</SPAN>
Scenario_2_Percent(Ln, 1) = Industry_Forecast_Tbl (x, 2)</SPAN>
Scenario_2_FTE(Ln, 1) = Industry_Forecast_Tbl (x, 2) * CY_Salary(Ln, 1)</SPAN>
Scenario_2_Actual(Ln, 1) = Industry_Forecast_Tbl (x, 2) * CY_Salary(Ln, 1) * PT_Perc(Ln, 1)</SPAN>
End If</SPAN>
End If</SPAN>
Next x</SPAN>
Next Ln</SPAN>
Range("Data_Tbl[Scenario 2 - Increase %]") = Scenario_2_Percent</SPAN>
Range("Data_Tbl[Scenario 2 -FTE Increase GBP]") = Scenario_2_FTE</SPAN>
Range("Data_Tbl[Scenario 2 -Actual Increase GBP]") = Scenario_2_Actual</SPAN>
End Function</SPAN>