Macro to last tab

Small spreadsheet with say 4 tabs.

Use a macro to do things in current sheet and then use ctrl PgDn to go to next sheet. I know its not the best way but will record. Works ok to next sheet.
On the last sheet, how do I exit macro and return to a specific ‘home’ sheet. First spreadsheet is home. Next spreadsheets are # 1,2,3. However not always the same number of sheets could be more. Say 8. So want to exit on last sheet, #8 in this case.

Does Calc know it is the last sheet, how do I tell it to go to ‘home’ sheet.

Thankyou

Charles Harris

googled to solved here Apache OpenOffice Community Forum - [Solved] Finding the last sheet number with a macro for Calc - (View topic)