The macro recorder in Google Sheets offers limited functionality. For more defined automation, like using custom functions, create a script with these steps:
Open a Google spreadsheet, and choose “Extensions -> Apps Script.” Delete any existing code in the script editor (on a new tab), add your code, and click “Save” to finish.