To write a macro in Microsoft Excel, you'll need to use the Visual Basic for Applications (VBA) programming language. Don't worry if you've never programmed before - writing macros in Excel is relatively easy and doesn't require any prior experience.
There are two ways to write macros in Excel - using the Visual Basic Editor (VBE), or using the Macro Recorder. The VBE is a more advanced option that gives you more control over your macros, but the Macro Recorder is much easier to use and is a great way to get started with writing macros.
Once you've written your macro, you can save it so that you can use it again in the future. Macros are saved as part of your workbook file, so they'll be available whenever you open that workbook.