Don't format the wrong partition or else Windows is gone and you
are left with Ubuntu.
And don't do the reverse, because Windows bootloader doesn't like
Linux bootloader.
Install Windows first, then install Linux.
Make sure you have at least 3 partitions, one for Windows, two for
Linux.
It's 2 for Linux because Linux virtual memory aka swap file uses
another partition, rather than eating up space the same partition
in Windows.
The rest, up to you to play. Damage anything, re-do everything.