How do I update a named range using a calc macro?

I know how to remove and add a named range using a macro, but that method breaks equations that reference a named range when it is deleted. Is there a way to directly modify the referenced cells of a named range by macro without using the delete/add method?

Thanks,
John Vickers

Hi,

You can change the referred cells with the “setContent” method of a com.sun.star.sheet.NamedRange object:

doc = thiscomponent
namedranges = doc.NamedRanges
myrange = namedranges.getByName("myrange")
myrange.setContent("$Sheet1.$B$1:$B$5")

Regards.

Worked like a charm! Thanks!