+ Reply to Thread
Results 1 to 5 of 5

Using CheckBox.Caption to determine the workseet name

Hybrid View

  1. #1
    Registered User
    Join Date
    12-10-2011
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Post Using CheckBox.Caption to determine the workseet name

    Hi,

    I have many checkboxes named under the file's worksheets. May I use CheckBox.Caption in order to go to a worksheet?

    My suggestion would be like that, but it's not working:

    
    Sub checkboxes()
    
    Dim i As Integer
        For i = 1 To 5
            If ActiveSheet.OLEObjects(i).Object.Value = True Then
               ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
               Sheets("ActiveSheet.OLEObjects(i).Object.Caption").Select
               Sheets("MAJ").Select
               Range("A1").Select
            End If
        Next i
    
    End Sub
    See an example in the file attached.

    Thanks for your help!
    Attached Files Attached Files
    Last edited by nicer2011; 12-20-2011 at 09:45 PM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Using CheckBox.Caption to determine the workseet name

    What happened when you tried it?

    Oh, I see the problem. As written "ActiveSheet.OLEObjects(i).Object.Caption" is being passed as a literal string.
    If you want to go to the sheet whose name is the caption, use this
    Sheets(ActiveSheet.OLEObjects(i).Object.Caption).Select
    Last edited by mikerickson; 12-20-2011 at 10:01 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-10-2011
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Using CheckBox.Caption to determine the workseet name

    I still have an error:

    Run time error 9: Subscript out of range

    Thanks

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    13,033

    Re: Using CheckBox.Caption to determine the workseet name

    Check the sheet names against the checkbox captions:
    Sub BensDebug()
        Dim i As Long
        Debug.Print "Sheet Name", "Name Length"
        For i = 1 To Sheets.Count
            Debug.Print Sheets(i).Name, Len(Sheets(i).Name)
        Next i
        
        Debug.Print
        Debug.Print "Caption Text", "Caption Text Length"
        
        For i = 1 To 5
            Debug.Print ActiveSheet.OLEObjects(i).Object.Caption, Len(ActiveSheet.OLEObjects(i).Object.Caption)
        Next i
    End Sub
    Results:
    Sheet Name    Name Length
     RA01          5 
     RA02          5 
     RA03          5 
     RA04          5 
     RA05          5 
    MAJ            3 
    
    Caption Text  Caption Text Length
    RA01           4 
    RA02           4 
    RA03           4 
    RA04           4 
    RA05           4
    Notice the spaces at the beginning of the actual sheet names, ergo, the caption <> sheet.name
    Last edited by protonLeah; 12-21-2011 at 12:38 AM.
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    12-10-2011
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Using CheckBox.Caption to determine the workseet name

    Hi,

    Thanks for your suggestion, protonLeah. I've changed the space at the beginning of the actual sheet names, but still not working - error 1004 this time

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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