Results 1 to 5 of 5

Thread: Excel: Focus from cell/combo to combo/cell [SELF-RESOLVED]

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Excel: Focus from cell/combo to combo/cell [SELF-RESOLVED]

    In excel, after I've typed data into a cell and hit return I want the focus to be set on a combobox, and after I've selected an item from the dropdown list I want the focus to be transferred to a different cell . How can I do this (with code)?
    Last edited by krtxmrtz; Jul 3rd, 2006 at 11:18 AM.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Focus from cell/combo to combo/cell

    Well, from combo to cell this code seems to work,
    VB Code:
    1. Private Sub ComboBox1_LostFocus()
    2.     If CheckBox4.Value Then
    3.         Range(ThisWorkbook.Names("Cell12")).Select
    4.     Else
    5.         Range(ThisWorkbook.Names("Cell13")).Select
    6.     End If
    7. End Sub
    but I still can't figure out how to do the first part.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Focus from cell/combo to combo/cell

    bump
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel: Focus from cell/combo to combo/cell [UNRESOLVED]

    if you have code worksheet_selectionchange sub, you should be able to do something based on the cell you would be going to move into

    VB Code:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    2. If Mid(Target.Address, 2, 1) = "E" Then Stop
    3. End Sub

    dunno quite where to go from there, but at least when you press enter it will run this sub

    pete

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Excel: Focus from cell/combo to combo/cell [UNRESOLVED]

    Finally I made it.
    VB Code:
    1. 'In a module:
    2. Global oldtarget As Range
    3. --------------------------------------------------------
    4. 'In ThisWorkbook:
    5. Private Sub Workbook_Open()
    6.     Range(ThisWorkbook.Names("StartCell")).Select
    7.     Set oldtarget = Range(ThisWorkbook.Names("StartCell"))
    8.     With ThisWorkbook.Sheets("Sheet1")
    9.        .EnableSelection = xlUnlockedCells
    10.        .Protect
    11.     End With
    12. 'Sheet1 is protected so that only a
    13. 'few unlocked cells can be selected
    14. End Sub
    15. --------------------------------------------------------
    16. 'In Sheet1:
    17. Private Sub ComboBox1_Click()
    18.     Application.Range("NextCell").Select
    19. End Sub
    20.  
    21. Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
    22. Shift As Integer)
    23.     If KeyCode = vbKeyReturn Then Application.Range("NextCell").Select
    24. End Sub
    25.  
    26. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    27.     ActiveSheet.Unprotect
    28.     If oldtarget.Address = Range(ThisWorkbook.Names("StartCell")).Address
    29. Then ComboBox1.Activate
    30.     Set oldtarget = Target
    31.     ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
    32. End Sub
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

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



Click Here to Expand Forum to Full Width