Search code examples
libreofficelibreoffice-calclibreoffice-basic

Using a Range in Calc Macro that is determined by highlighted cells, not an absolute cell reference


Simple request: I have calc sheets with multiple tables of data, needing to be sorted by values I have defined (this UserDefIndex is all set)? I am hoping to find a way to write the Macro that will perform this sort on the cells I have highlighted, as opposed to an absolute cell address

I have wandered through each of these, however, the nomenclature is just too obtuse, and I am having difficulty gaining any grasp of the code

How do I define an area of highlighted cells, as opposed to "$A$3:$D$18", since the size of the range will vary?


Solution

  • You can select the range manually, then get the selection range

    Doc = ThisComponent
    Sheet = Doc.Sheets(0)
    rng = Doc.CurrentSelection