How to make a sort happen automatically as the values are entered

I have a spreadsheet with two worksheets - ScoreSheet and Results. It will be used in an upcoming local golf tournament. There are 12 teams, and as their scores come in, they are entered into the ScoreSheet. Aside from column titles, the Results worksheet is completely populated from the ScoreSheet. Sort Ascending on column C is configured, but it isn’t working in “real time”, i.e., as the scores come in. Teams 1-12 will finish in order, but as those teams’ names and scores are pulled in to Results worksheet, they are still showing up in that order, not sorted by score. Can that be made to happen automatically so that the sort will not require user intervention to occur? TIA!

OS is Windows 10, LO is 7.6.2.1

menu:Data>Refresh refreshes a defined database range with current sort order and filter settings. You may assign a keyboard shortcut or a custom toolbar button to it. Or put a push button directly on sheet with URL .uno:DataAreaRefresh

1 Like

A simple macro driven approach:

Sub Sort_Data(rg)
	dbr = ThisComponent.DatabaseRanges.getByName("Data")
	addr = dbr.getDataArea()
	if rg.queryIntersection(addr).getCount() > 0 then dbr.refresh()
End Sub

where “Data” should be replaced with the name of your actual database range.
Right-click the sheet tab, choose “Sheet Events” and assign the “Content changed” event to the above macro. It refreshes the database range when content changed within the specified database range.

Here is a solution using many additional columns (that you can hide later on). The idea is to rank the scores using the RANK function, then to display them in order using VLOOKUP on the Result sheet.

ScoreResult.ods (16.4 KB)