Results 1 to 4 of 4

VBA Control Button Help

Threaded View

  1. #1
    Registered User
    Join Date
    10-20-2009
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    7

    VBA Control Button Help

    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.
    Last edited by Vittorio; 10-28-2009 at 10:20 AM. Reason: problem solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1