+ Reply to Thread
Results 1 to 7 of 7

Thread: Select a Combo Box when a SPECIFIC Cell Changes

  1. #1
    Registered User
    Join Date
    11-29-2008
    Location
    Littleton, CO
    Posts
    12

    Select a Combo Box when a SPECIFIC Cell Changes

    Hi,

    I am new to this site and relatively new to programming.

    I am trying to use vba to give a combo box focus only when cell D2 (a cell merge of d2,d3 and d4) changes.

    So, If I enter a number in cell D2 and hit ENTER or use one of the arrows I want the combo box to get selected (get focus). I don't want this action to take place when other cells are acted upon this way. ONLY D2.

    Thanks.
    Last edited by coachdave; 12-04-2008 at 03:22 PM. Reason: Solved

  2. #2
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952

    Thumbs down

    Welcome to the forum!

    If you are using a Control Toolbox combobox named ComboBox1, right click your sheet, View Code and paste:
    Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Address <> "$D$2" Then Exit Sub
      ComboBox1.Activate
      ComboBox1.DropDown
    End Sub
    Last edited by Kenneth Hobson; 11-29-2008 at 06:24 PM.

  3. #3
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566
    Hi,

    You'll need to go into the VB Environment and use the Worksheet SelectionChange event and use an instruction like for instance

    If Target = Range("D2") Then
        'whatever you want your code to do
    End If
    
    HTH

  4. #4
    Registered User
    Join Date
    11-29-2008
    Location
    Littleton, CO
    Posts
    12

    Still having trouble

    Both of you answers seem simple enough but I am getting no action ahen cell D2 is selected and I hit enter or use the arrows. The combobox is not active and the list does not drop down.

    The name of the ActiveX control is cboSeasonal. When I name it in the code the option to activae and to dropdown are available.

    Here is how I entered the code:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    If Target.Address <> "D2" Then Exit Sub

    cboSeasonal.Activate
    cboSeasonal.DropDown


    End Sub

  5. #5
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952
    Maybe you want to use the Select event range than Change? Enter causes no change. Not sure what you mean by arrow key. Of course arrow keys do not trigger the Change event either.

    Your code will always exit because you are comparing an absolute address to relative address. Change one or the other. Notice that I used $D$2.

    Typically, I would use Intersect() to check for more than one cell that might change. I gave you the more simple example.

  6. #6
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952
    Maybe you want to use the Select event range than Change? Enter causes no change. Not sure what you mean by arrow key. Of course arrow keys do not trigger the Change event either.

    Your code will always exit because you are comparing an absolute address to relative address. Change one or the other. Notice that I used $D$2.

    Typically, I would use Intersect() to check for more than one cell that might change. I gave you the more simple example.

  7. #7
    Registered User
    Join Date
    11-29-2008
    Location
    Littleton, CO
    Posts
    12

    Thumbs up Thank You Kenneth

    Changing from Worksheet_SelectionChange to Worksheet_Change did the trick.

    Thank you for your time and effort.

    coachdave

+ 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.2.0