Welcome to the MrExcel board!
Are you looking to do this ..
- manually
- by formulas
- with a macro?
Can you give us a bit more detail about what you have, where and what you are trying to achieve and perhaps a small set of dummy data & any further explanation in relation to that sample data? My signature block below has a link with suggestions for good ways to provide sample data that we can copy/paste to test with.