+ Reply to Thread
Results 1 to 4 of 4

UserForm Combobox Value based on Worksheet selection (2007)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    UserForm Combobox Value based on Worksheet selection (2007)

    Good day,
    having trouble with the following here:

    Private Sub ComboBox2_Enter()
    If Worksheets("Sheet 1").Select Then
        With ComboBox2
            ComboBox2.Clear
            ComboBox2.AddItem "Group 1"
            ComboBox2.AddItem "Group 3"
        End With
    End If
    
    If Worksheets("Sheet 2").Select Then
        With ComboBox2
            ComboBox2.Clear
            ComboBox2.AddItem "Group 5"
            ComboBox2.AddItem "Group 6"
        End With
    End If
    End Sub
    What I am trying to do is if I am in Sheet 1 then populate the userform combobox2 with, example "Group 1" and "Group 3"
    If I am in Sheet 2 then populate my Combobox with "Group 5" and "Group 6"

    That code is bringing me to the worksheet itself... what should I change the ".Select" to...

  2. #2
    Forum Contributor
    Join Date
    09-24-2013
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: UserForm Combobox Value based on Worksheet selection (2007)

    Try this..
    Private Sub ComboBox2_Enter()
    If Worksheets("Sheet 1").Select Then
        With ComboBox2
            ComboBox2.Clear
            ComboBox2.AddItem "Group 1"
            ComboBox2.AddItem "Group 3"
        End With
    elseIf Worksheets("Sheet 2").Select Then
        With ComboBox2
            ComboBox2.Clear
            ComboBox2.AddItem "Group 5"
            ComboBox2.AddItem "Group 6"
        End With
    End If
    End Sub
    This has not been tested...

  3. #3
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox Value based on Worksheet selection (2007)

    Tested and it doesn't seem to work it goes back to my Sheet 1 everytime I select another worksheet...

  4. #4
    Forum Contributor
    Join Date
    03-29-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    818

    Re: UserForm Combobox Value based on Worksheet selection (2007)

    Working Code (From Roy on Ozgrid)

    Private Sub ComboBox2_Enter() 
        With Me.combobox2 
            Select Case ActiveSheet.Name 
            Case "Sheet1": .List = Array("Group 1", "Group 3") 
            Case "Sheet2": .List = Array("Group 5", "Group 6") 
            Case "Sheet 3": .List = Array("Group 7") 
            Case "Sheet 4": .List = Array("Group 2", "Group 4") 
            End Select 
        End With 
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Change Userform Label based on ComboBox Selection
    By rbyrd023 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-02-2014, 09:25 AM
  2. [SOLVED] Pre populating a userform from excel based on combobox selection
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2013, 12:09 PM
  3. [SOLVED] Change Labels in Userform based on selection in ComboBox
    By johnw993 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-03-2013, 10:52 PM
  4. [SOLVED] Based on userform combobox selection find text on worksheet
    By afpPaul in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2012, 08:07 AM
  5. Populating a userform based on a combobox selection
    By blindzero678 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-22-2010, 03:37 PM

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