Excel text box VBA

G

Guest

I've entered a text box into my worksheet from the Control Toolbox toolbar.

When entering text into the box, how can I get the cursor to return to a
cell in the worksheet after entry has been completed?

I tried the following:

Private Sub TextBox1_Change()

Range("A1").Select

End Sub

But the cursor moved to cell A1 as soon as I started typing text in the box.

Regards
 
G

Guest

You probably want the lost focus event instead fo the change event...

Private Sub TextBox1_LostFocus()
Range("A1").Select
End Sub
 
F

Flemming

Hi,

This works when you enter your text and pres ESC

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii.Value = vbKeyEscape Then
Range("A1").Select
End If
End Sub

Cheers,
Flemming
 
G

Guest

R,

What will indicate that text entry has finished? If pressing the ENTER key
would indicate that data entry is finished, then you can trap it in the
Keydown event.

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Then Range("A1").Select 'EnterkEy
End Sub
 
G

Guest

Hello Jim,
Just a head's up to the you/OP, but hitting Enter or Return in a Textbox on
a worksheet doesn't remove the cursor from the textbox and the textbox
doesn't lose focus, so I don't think this will be effective.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top