Macro for getting the selection's upper left and lower right cells

A rectangular group of cells is selected with the cursor on the sheet. How can I get the numbers of the first row, first column, and last row, last column of this group in a macro? I assume that I need to use ThisComponent.getCurrentController(), but I don’t know how exactly.

	selection = ThisComponent.CurrentController.Selection
	
	ra = selection.RangeAddress
	
	message = "First Row: " + ra.StartRow + CHR(13) + "First Column:" + ra.StartColumn + _
		CHR(13) + "End Row: " + ra.EndRow + CHR(13) + "End Column:" + ra.EndColumn
	
	MsgBox message

1 Like

Macros/Basic/Calc/Ranges - The Document Foundation Wiki

Many thanks for a lot of info.