Changing a cell value in a duplicate row

Clash Royale CLAN TAG#URR8PPPChanging a cell value in a duplicate row
Thanks in advance for any help, i'm having a mental block!
It's a long story as to why but I have a table like the following:
Start Date End Date Reference
02/07/2017 01/07/2018 2331851720712
01/04/2017 31/12/2017 1200025264898
01/02/2017 31/12/2017 1200025264912
08/05/2017 07/06/2017 2000054765267
10/06/2017 10/07/2017 2000054765267
The bottom two rows have the same reference number AND the End Date of the first occurance is in the same month as the Start Date of the second occurance. When this happens I need the first occurance End date to change to the 31st of the previous month.
Any thoughts would be hugely appreciated!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.