Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Create a small Userform. Put two TextBoxes in it. Add the following
code. Private Sub UserForm_Initialize() TextBox1.Value = "0.00" TextBox2.Value = "0.00" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode _ As MSForms.ReturnInteger, _ ByVal Shift As Integer) Dim sHours As String Dim v As Integer Select Case KeyCode Case 37 ' Left v = -1 Case 38 v = 4 Case 39 ' Right v = 1 Case 40 v = -4 Case Else v = 0 End Select sHours = TextBox1.Text If IsNumeric(sHours) And v < 0 Then sHours = sHours + v * 0.25 If sHours < 0 Then sHours = 0 TextBox1.Text = Format(sHours, "#0.00") End If End Sub Private Sub TextBox2_KeyDown(ByVal KeyCode _ As MSForms.ReturnInteger, _ ByVal Shift As Integer) Dim sHours As String Dim v As Integer Select Case KeyCode Case 37 ' Left v = -1 Case 38 v = 4 Case 39 ' Right v = 1 Case 40 v = -4 Case Else v = 0 End Select sHours = TextBox2.Text If IsNumeric(sHours) And v < 0 Then sHours = sHours + v * 0.25 If sHours < 0 Then sHours = 0 TextBox2.Text = Format(sHours, "#0.00") End If End Sub When the boxes are stacked, pressing the up arrow in the upper box has the desired effect but pressing the down arrow increments the amount by -1.00 then the cursor/focus jumps to the lower box. Similar opposite behavior in the lower box. This does not happen when the boxes are side-by-side. Can I control this, keep cursor/focus in boxes when stacked? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Put KeyCode = 0 at the end of both of your KeyDown events. This cancels the keystroke. Cordially, Chip Pearson Microsoft Most Valuable Professional, Excel, 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com On Sat, 20 Mar 2010 13:42:11 -0700 (PDT), Slim Slender wrote: Create a small Userform. Put two TextBoxes in it. Add the following code. Private Sub UserForm_Initialize() TextBox1.Value = "0.00" TextBox2.Value = "0.00" End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode _ As MSForms.ReturnInteger, _ ByVal Shift As Integer) Dim sHours As String Dim v As Integer Select Case KeyCode Case 37 ' Left v = -1 Case 38 v = 4 Case 39 ' Right v = 1 Case 40 v = -4 Case Else v = 0 End Select sHours = TextBox1.Text If IsNumeric(sHours) And v < 0 Then sHours = sHours + v * 0.25 If sHours < 0 Then sHours = 0 TextBox1.Text = Format(sHours, "#0.00") End If End Sub Private Sub TextBox2_KeyDown(ByVal KeyCode _ As MSForms.ReturnInteger, _ ByVal Shift As Integer) Dim sHours As String Dim v As Integer Select Case KeyCode Case 37 ' Left v = -1 Case 38 v = 4 Case 39 ' Right v = 1 Case 40 v = -4 Case Else v = 0 End Select sHours = TextBox2.Text If IsNumeric(sHours) And v < 0 Then sHours = sHours + v * 0.25 If sHours < 0 Then sHours = 0 TextBox2.Text = Format(sHours, "#0.00") End If End Sub When the boxes are stacked, pressing the up arrow in the upper box has the desired effect but pressing the down arrow increments the amount by -1.00 then the cursor/focus jumps to the lower box. Similar opposite behavior in the lower box. This does not happen when the boxes are side-by-side. Can I control this, keep cursor/focus in boxes when stacked? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Chip, that did the trick.
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to prevent focus by clicking combo box ? | Excel Programming | |||
Prevent control taking focus when accelerator key is used? | Excel Programming | |||
cursor focus in excel | Excel Discussion (Misc queries) | |||
How to prevent cursor from moving behind filled cells | Excel Discussion (Misc queries) | |||
Cursor Keys does not change cell focus | Excel Discussion (Misc queries) |