olivespickles
New Member
- Joined
- Apr 6, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
- Web
Hi all,
I am working on a macro to complement something I have already written, where the user inputs the required finish date, and the macro automatically calculates start dates for 5 project phases that need to happen before the finish date. Each phase takes 1 month, therefore phase 1 starts 5 months before the finish date, phase 2 starts 4 months before the finish date, etc.
i am working on an extra function where I want the user to be able to change the start date of one project phase or more (within the cell), and this macro will automatically calculate the subsequent start dates of the later phases according to the new date. Eg. the original finish date was 31 May 2021 and the expected phase 1 start date was 01 Jan 2021 (5 months before finish), but phase 1 started late and the actual start date is now 01 Feb 2021, which means that all the other dates will be 1 month later than originally calculated. This is the code I have so far:
Currently I am having a problem where Excel defaults all my year dates to 1900 and doesn't recalculate new dates based on the "actual" start dates I input. I am not sure where I'm going wrong? Would appreciate some advice on this, thanks!
I am working on a macro to complement something I have already written, where the user inputs the required finish date, and the macro automatically calculates start dates for 5 project phases that need to happen before the finish date. Each phase takes 1 month, therefore phase 1 starts 5 months before the finish date, phase 2 starts 4 months before the finish date, etc.
i am working on an extra function where I want the user to be able to change the start date of one project phase or more (within the cell), and this macro will automatically calculate the subsequent start dates of the later phases according to the new date. Eg. the original finish date was 31 May 2021 and the expected phase 1 start date was 01 Jan 2021 (5 months before finish), but phase 1 started late and the actual start date is now 01 Feb 2021, which means that all the other dates will be 1 month later than originally calculated. This is the code I have so far:
VBA Code:
'old date variables
Sheets("X").Cells(outputrow, 5) = finish
Sheets("X").Cells(outputrow, 6) = start_phase1
Sheets("X").Cells(outputrow, 9) = start_phase2
Sheets("X").Cells(outputrow, 15) = start_phase3
Sheets("X").Cells(outputrow, 18) = start_phase4
Sheets("X").Cells(outputrow, 21) = start_phase5
'Date recalculations
finish = CDate(finish)
start_phase1 = CDate(start_phase1)
start_phase2 = CDate(start_phase2)
start_phase3 = CDate(start_phase3)
start_phase4 = CDate(start_phase4)
start_phase5 = CDate(start_phase5)
'conditions
If start_phase1 = finish - 150 Then
start_phase1 = start_phase1
Else
start_phase2 = start_phase1 + 30
start_phase3 = start_phase2 + 30
start_phase4 = start_phase3 + 30
start_phase5 = start_phase4 + 30
finish = start_phase5 + 30
End If
If start_phase2 = finish - 120 Then
start_phase2 = start_phase2
Else
start_phase3 = start_phase2 + 30
start_phase4 = start_phase3 + 30
start_phase5 = start_phase4 + 30
finish = start_phase5 + 30
End If
If start_phase3 = finish - 90 Then
start_phase3 = start_phase3
Else
start_phase4 = start_phase3 + 30
start_phase5 = start_phase4 + 30
finish = start_phase5 + 30
End If
If start_phase4 = finish - 60 Then
start_phase4 = start_phase4
Else
start_phase5 = start_phase4 + 30
finish = start_phase5 + 30
End If
If start_phase5 = finish - 30 Then
start_phase5 = start_phase5
Else
finish = start_phase5 + 30
End If
Currently I am having a problem where Excel defaults all my year dates to 1900 and doesn't recalculate new dates based on the "actual" start dates I input. I am not sure where I'm going wrong? Would appreciate some advice on this, thanks!