The sample sheet is attached here.
Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Dim shname As String
Dim n As Integer
For Each ws In Worksheets
'CommanButton1 is the name of CommandButton which is being clicked
shname = Right(CommandButton1.Caption, Len(CommandButton1.Caption) - 7)
On Error Resume Next
n = WorksheetFunction.Search(shname, ws.Name)
On Error GoTo 0
If n > 0 Then
'sample code
ws.Range("A1") = shname
'do stuff here
End If
n = 0
Next ws
End Sub
Private Sub CommandButton2_Click()
Dim ws As Worksheet
Dim shname As String
Dim n As Integer
For Each ws In Worksheets
'CommanButton1 is the name of CommandButton which is being clicked
shname = Right(CommandButton2.Caption, Len(CommandButton2.Caption) - 7)
On Error Resume Next
n = WorksheetFunction.Search(shname, ws.Name)
On Error GoTo 0
If n > 0 Then
'sample code
ws.Range("A1") = shname
'do stuff here
End If
n = 0
Next ws
End Sub
Bookmarks