Created attachment 124070 [details] Minimal spreadsheet exhibiting error Windows 10 I have two named ranges in the same column, but their ReferencePosition.Column values are different, when I would anticipate them to be the same. The attached spreadsheet (cut down from the one I was working on to bare essentials) illustrates this, with the okay range (Tst2) highlighted green and the bad one (DataW1C) red. You can see if you choose the named ranges from the gui droplist that they jump to these locations. They have the same column, but if you open spreadsheet (enable macros) and run the Main() code, which is below, the code reports different columns. Cheers, David SPREADHEET CODE: Option Explicit Sub Main() Msgbox ThisComponent.NamedRanges.getByName("DataW1C").ReferencePosition.Column ' Fail (Red) Msgbox ThisComponent.NamedRanges.getByName("Tst2").ReferencePosition.Column ' Good (Green) End Sub
There is no error. DataW1C was defined on 'BALANCED SL'.$I$8 to point to $'BALANCED SL'.$J$8 Tst2 was defined on 'BALANCED SL'.$J$4 to point to $'BALANCED SL'.$J$4 Which is the difference you get with ReferencePosition.Column Don't confuse the reference position (the base cell address where the range is defined on) with a reference the expression is pointing to.
Thanks - I see that now! .ReferredCells.RangeAddress.StartColumn seems to work better. Thanks for your pointer. I did have an issue where ThisComponent.NamedRanges.getByName(NameString).Name<>NameString ie where the wrong (but existing) ranges were being returned by name lookup so I assumed the fault had been here too. (For that other error, I recreated all the ranges and that went away.) Cheers, d