The first thing you need to take into account is that a Macro cant be in a .xlsx workbook. Trying saving the one with the macro as a .xlsm (macro enabled workbook), you also need to the code into a Module
Have a read of some of the blogs on here
https://www.myonlinetraininghub.com/category/excel-vba
This one shows you how to record a macro to start with
https://www.myonlinetraininghub.com/...macro-in-excel