Friday, 5 July 2013

Select a sheet based on button label/caption

A little trick I wrote this morning. Add this code to a module in your excel worksheet, then Assign Macro on a button. The label of the button will determine which sheet will be activated.

Sub SheetSelect()
'Code by paul.alford@ee.co.uk
'v1, 05 July 2013
'-------------------------------

On Error GoTo error1

Dim labelText As String
labelText = ActiveSheet.Buttons(Application.Caller).Caption
Sheets(labelText).Activate

error1:
MsgBox "Sorry couldn't open the " & labelText & " sheet."

End Sub

No comments:

Post a Comment