How do I alter the code in this BASIC macro to use named ranges instead of the cell numbers in the range?

May I suppose you still misunderstand the few lines of Basic code @Villeroy posted as “code snippets” or as a suggestion how to modify your code?
In fact they only exemplify how (in principle) you can get and use access to services of the LibO AP related to your concern. I also hinted in a previous post that the Calc document and every sheet contained in it have a property .NamedRanges - and where the relevant difference (scope) lies.
You can’t make use of such information by copy/paste. You need to study it to a certain level of understanding before you can make use of it. Some experiments (not done in a “production” document!) will be needed on the way.
Well‚ my own understanding of anything is also incomplete, but on no level whatever it can be shared by copy/paste.