ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel text box VBA (https://www.excelbanter.com/excel-programming/394662-excel-text-box-vba.html)

R Ormerod

Excel text box VBA
 
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

--
R Ormerod

Jim Thomlinson

Excel text box VBA
 
You probably want the lost focus event instead fo the change event...

Private Sub TextBox1_LostFocus()
Range("A1").Select
End Sub
--
HTH...

Jim Thomlinson


"R Ormerod" wrote:

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

--
R Ormerod


Flemming[_2_]

Excel text box VBA
 
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


"R Ormerod" wrote in message
...
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

--
R Ormerod




Vergel Adriano

Excel text box VBA
 
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



--
Hope that helps.

Vergel Adriano


"R Ormerod" wrote:

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

--
R Ormerod


Tom Ogilvy

Excel text box VBA
 
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.

--
Regards,
Tom Ogilvy


"Jim Thomlinson" wrote:

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

Private Sub TextBox1_LostFocus()
Range("A1").Select
End Sub
--
HTH...

Jim Thomlinson


"R Ormerod" wrote:

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

--
R Ormerod



All times are GMT +1. The time now is 05:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com