Hi,
Here is what i am currently using as code for one of my 56 or so buttons:
Private Sub CommandButton8_Click()
Dim i As String
i = "Mathematics"
Sheets("Subjects").Select
On Error GoTo ErrorHandler
ActiveSheet.PivotTables("PivotTable1").PivotFields("Class").CurrentPage _
= i
ErrorHandler:
MsgBox i & " does not exist. Please press OK and choose another button.", vbOKOnly
Sheets("Summary").Select
Exit Sub
End Sub
And here are the challenges i'm getting so far:
#1
The message box is only supposed to pop-up if "i" is not found on the "Subjects" worksheet. However, what i am getting is the msgbox even if "i" is found or valid. Is there something wrong with my syntax or the order it was written?
#2
How do i type the message box content so that it reads:
"Mathematics" does not exist. Please press OK and choose another button.
instead of:
Mathematics does not exist. Please press OK and choose another button.
Please note the "" marks.
#3
This is just an add-on question. For worksheets with multiple buttons, is there a way to format the code so that it works for all instead of typing it separately for each "i"?
Thanks guys. Looking forward to your help.
Bookmarks