|
-
Jun 25th, 2006, 08:00 AM
#1
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)
-
Jun 25th, 2006, 08:38 AM
#2
Re: Excel: Focus from cell/combo to combo/cell
Well, from combo to cell this code seems to work,
VB Code:
Private Sub ComboBox1_LostFocus()
If CheckBox4.Value Then
Range(ThisWorkbook.Names("Cell12")).Select
Else
Range(ThisWorkbook.Names("Cell13")).Select
End If
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)
-
Jun 26th, 2006, 05:04 AM
#3
Re: Excel: Focus from cell/combo to combo/cell
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)
-
Jun 26th, 2006, 07:41 AM
#4
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:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Mid(Target.Address, 2, 1) = "E" Then Stop
End Sub
dunno quite where to go from there, but at least when you press enter it will run this sub
pete
-
Jul 3rd, 2006, 11:17 AM
#5
Re: Excel: Focus from cell/combo to combo/cell [UNRESOLVED]
Finally I made it.
VB Code:
'In a module:
Global oldtarget As Range
--------------------------------------------------------
'In ThisWorkbook:
Private Sub Workbook_Open()
Range(ThisWorkbook.Names("StartCell")).Select
Set oldtarget = Range(ThisWorkbook.Names("StartCell"))
With ThisWorkbook.Sheets("Sheet1")
.EnableSelection = xlUnlockedCells
.Protect
End With
'Sheet1 is protected so that only a
'few unlocked cells can be selected
End Sub
--------------------------------------------------------
'In Sheet1:
Private Sub ComboBox1_Click()
Application.Range("NextCell").Select
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = vbKeyReturn Then Application.Range("NextCell").Select
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect
If oldtarget.Address = Range(ThisWorkbook.Names("StartCell")).Address
Then ComboBox1.Activate
Set oldtarget = Target
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|