Consulting

Results 1 to 5 of 5

Thread: Adding same items to combo boxes on multiple sheets

  1. #1

    Adding same items to combo boxes on multiple sheets

    Thanks in advance for any help.

    In this workbook I have several(about 25) worksheets, each of which has 3 combo boxes on them, which I want to use to navigate between the different worksheets. So the items in each combobox will be the same on each sheet.

    What I want to do is run some module based code that will propulate the active sheets combo box, the comboboxes are named the same on each sheet.

    The code I was thinking about would be something like:


    SheetName.cboOne.Additem "Item1"

    Where SheetName woud change depending upon the active sheet.

    The problem I have is assigning the sheet name to some sort of variable which would achieve this.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Rather than worrying about ea sheet's name, maybe we can use the Workbook's SheetActivate event.

    In ThisWorkbook module:
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
        Dim wks As Worksheet
        Dim objMeComboBox As OLEObject
        If TypeName(Sh) = "Worksheet" Then
            Set wks = ActiveSheet
            On Error Resume Next
            Set objMeComboBox = wks.OLEObjects("ComboBox1")
            On Error GoTo 0
            If Not objMeComboBox Is Nothing Then
                With objMeComboBox.Object
                    .Clear
                    .AddItem "Item1"
                End With
            End If
        End If
    End Sub
    Does that help?

    Mark

  3. #3
    Thanks for this, it was just what I need. Sorry for delay getting back been working.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by tony2501
    Thanks for this, it was just what I need. Sorry for delay getting back been working.
    You are most welcome and I'm glad it helped

  5. #5
    VBAX Regular
    Joined
    Jan 2012
    Posts
    12
    Location

    problem plz help

    I want to use combobox (first combobox) to choose between multiple worksheets. So when i chose in first combobox some of my sheets, other data in form needs to be placed into the worksheet that i picked in first combo box.
    is that posible?
    i tried many ways to do it but it doesnt work. plz help

Posting Permissions

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