Calc macros: can I copy a varying number of rows

I am using Calc for my club. I enter a name in column A, tag number in column B, and a score in column C. Every name has a score, but not all names have a tag number. I recorded a macro which sorts by tag number, and that groups the ones with a tag number together. I now want to write a macro to sort the name and score of only those with tag numbers. The number of names and tag number varies from week to week, so I can’t record the action. so:

1 - Is it possible to sort a varying number of rows, based on how many tag numbers there are?
and, 2 - can anyone tell me the code to accomplish that?

Thanks!

I’ve tried using PivotTable, maybe it solves your problem.

For a better suggestion, post an example file.