PDA

View Full Version : Solved: leave the ActiveX text box, pressing 'Enter'



marreco
07-30-2012, 05:02 PM
hi, when typing in a text box ActiveX, you can press the 'Enter' key and exit the text box to a cell in the worksheet?

Kenneth Hobs
07-30-2012, 07:59 PM
Set the userform's ShowModal property value to False and then:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbCr Then Range("A1").Select
End Sub

marreco
07-31-2012, 04:17 AM
Hi.
How do I adapt to my code?
Private Sub TextBox1_LostFocus()
If Trim(TextBox1.Value) > vbNullString Then
Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:=TextBox1.Value
ElseIf ActiveSheet.AutoFilterMode Then
Range("A1").CurrentRegion.AutoFilter
End If
End Sub
Thank you!!

Kenneth Hobs
07-31-2012, 06:09 AM
Private Sub TextBox1_LostFocus()
FilterNow
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = vbCr Then
FilterNow
Range("A1").Select
End If
End Sub
Private Sub FilterNow()
If Trim(TextBox1.Value) > vbNullString Then
Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:=TextBox1.Value
ElseIf ActiveSheet.AutoFilterMode Then
Range("A1").CurrentRegion.AutoFilter
End If
End Sub

marreco
07-31-2012, 09:18 AM
Hello Kenneth Hobs, I'm having an error.
If I try to type in the text box ActiveX generates error
Run-time error '13 '
type Mismatch

Thank you!!!

Kenneth Hobs
07-31-2012, 09:28 AM
Change vbCr to 13 or Asc(vbCr).

marreco
07-31-2012, 09:34 AM
was great, perfect, thank you very much!:rotlaugh:

I do not know why I can not mark the post as solved, if you (or the moderator) can do for me, I'll be thankful once again