I have a function that gathers the name of sheet 4
Function LastSheetName()
Application.Volatile True
LastSheetName = Worksheets(4).Name
End Function
Then I want to output this name within a cell on my worksheet
=LastSheetName()
This works as intended.
However, sheet 4 will be deleted, added and will have a different name each time.
Now the formula on my sheet doesn't update when a new sheet 4 is added like I want it to. It stays as #VALUE!, as obviously it was looking at the old sheet 4, then the sheet was deleted, before the new sheet 4 was in place.
I need something to add at the end of my code for the "Add Sheet" button that refreshes this formula =LastSheetName()
after it has added the new sheet 4.
I have tried adding application.Volatile
to the beginning of my function, like above, with no success.
I have tried adding
Worksheets(4).EnableCalculation = False
Worksheets(4).EnableCalculation = True
To the end of my code, no success either.
EDITL Sheet 4 not 6 sorry