Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Controlling tab order on a sheet to include AX combos
Try the following code in the Sheet code module for the sheet that contains
the Comboboxes. This will work with any number of comboboxes. The TopLeftCell property of each control is tested against Target. If TopLeftCell.Row = Target.Row AND (TopLeftCell.Column = Target.Column OR TopLeftCell.Column = Target.Column -1) then drop down the combobox list set set focus to the control. Option Explicit Private OLEObjs As Collection Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim OLEObj As OLEObject ''''''''''''''''''''''''''''''''''''''''''' ' If this is the first time through, ' load up the collection with Comboboxes. ''''''''''''''''''''''''''''''''''''''''''' If OLEObjs Is Nothing Then Set OLEObjs = New Collection For Each OLEObj In Me.OLEObjects If TypeOf OLEObj.Object Is MSForms.ComboBox Then OLEObjs.Add Item:=OLEObj, key:=OLEObj.Name End If Next OLEObj End If ''''''''''''''''''''''''''''''''''''''''''''' ' If more than one cell is selected, get out. ''''''''''''''''''''''''''''''''''''''''''''' If Target.Cells.Count 1 Then Exit Sub End If '''''''''''''''''''''''''''''''''''''''''''''''''' '''''' ' Loop through the OLEObjs, and try to find one whose ' TopLeftCell is in the same rows as Target and ' TopLeftCell is in the same column or one column to ' the left of Target. '''''''''''''''''''''''''''''''''''''''''''''''''' '''''' For Each OLEObj In OLEObjs With OLEObj.TopLeftCell If .Row = Target.Row And _ (.Column = Target.Column Or .Column = Target.Column - 1) Then '''''''''''''''''''''''''''''''''''''''''''''''' ' We found the appropriate combobox. Drop down ' the list and set focus to the combobox. '''''''''''''''''''''''''''''''''''''''''''''''' OLEObj.Object.DropDown OLEObj.Verb xlVerbPrimary Exit For End If End With Next OLEObj End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "XP" wrote in message ... I am using Office 2003 on Windows XP. I have a sheet designed into a form in which certain cells are locked and certain cells unlocked for completion, etc. On this form there are some ActiveX combo boxes that I would like included if the user tabs from cell to cell. Right now, the combo boxes are ignored, but I would like, say when the user tabs from a cell that preceeds a combo box for the cursor to go to the combo box and open the drop down so the user can start typing or pick from the list. 1. Is this possible? 2. How can I make it work? 3. If possible can an example be posted? 4. Thanks sincerely in advance for your assistance. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Controlling tab order on a sheet to include AX combos
I had the column test backwards.
(.Column = Target.Column Or .Column = Target.Column - 1) Then should be (.Column = Target.Column Or .Column - 1 = Target.Column) Then "Chip Pearson" wrote in message ... Try the following code in the Sheet code module for the sheet that contains the Comboboxes. This will work with any number of comboboxes. The TopLeftCell property of each control is tested against Target. If TopLeftCell.Row = Target.Row AND (TopLeftCell.Column = Target.Column OR TopLeftCell.Column = Target.Column -1) then drop down the combobox list set set focus to the control. Option Explicit Private OLEObjs As Collection Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim OLEObj As OLEObject ''''''''''''''''''''''''''''''''''''''''''' ' If this is the first time through, ' load up the collection with Comboboxes. ''''''''''''''''''''''''''''''''''''''''''' If OLEObjs Is Nothing Then Set OLEObjs = New Collection For Each OLEObj In Me.OLEObjects If TypeOf OLEObj.Object Is MSForms.ComboBox Then OLEObjs.Add Item:=OLEObj, key:=OLEObj.Name End If Next OLEObj End If ''''''''''''''''''''''''''''''''''''''''''''' ' If more than one cell is selected, get out. ''''''''''''''''''''''''''''''''''''''''''''' If Target.Cells.Count 1 Then Exit Sub End If '''''''''''''''''''''''''''''''''''''''''''''''''' '''''' ' Loop through the OLEObjs, and try to find one whose ' TopLeftCell is in the same rows as Target and ' TopLeftCell is in the same column or one column to ' the left of Target. '''''''''''''''''''''''''''''''''''''''''''''''''' '''''' For Each OLEObj In OLEObjs With OLEObj.TopLeftCell If .Row = Target.Row And _ (.Column = Target.Column Or .Column = Target.Column - 1) Then '''''''''''''''''''''''''''''''''''''''''''''''' ' We found the appropriate combobox. Drop down ' the list and set focus to the combobox. '''''''''''''''''''''''''''''''''''''''''''''''' OLEObj.Object.DropDown OLEObj.Verb xlVerbPrimary Exit For End If End With Next OLEObj End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email address is on the web site) "XP" wrote in message ... I am using Office 2003 on Windows XP. I have a sheet designed into a form in which certain cells are locked and certain cells unlocked for completion, etc. On this form there are some ActiveX combo boxes that I would like included if the user tabs from cell to cell. Right now, the combo boxes are ignored, but I would like, say when the user tabs from a cell that preceeds a combo box for the cursor to go to the combo box and open the drop down so the user can start typing or pick from the list. 1. Is this possible? 2. How can I make it work? 3. If possible can an example be posted? 4. Thanks sincerely in advance for your assistance. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating and Controlling a User data Entry Sheet | Excel Discussion (Misc queries) | |||
combos and dates | Excel Programming | |||
too many combos | Excel Programming | |||
one sub for many Combos in different way | Excel Programming | |||
Controlling Tab order | Excel Programming |