Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
(snip rest of thread -it's about an autocomplete Forms2 textbox)
"Rich Cooper" skrev i melding ... Coud i ask for your help to getting the backspace key to work. I would appreciate that. Ok. I never did this in VBA before, but I believe this is pretty close. Complete code: Option Explicit Dim blnAuto As Boolean Private Sub TextBox1_KeyDown(ByVal KeyCode As _ MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 8 'Backspace TextBox1.SelText = "" If TextBox1.SelStart 0 Then _ TextBox1.SelStart = TextBox1.SelStart - 1 TextBox1.SelLength = Len(TextBox1.Text) - TextBox1.SelStart Case Else End Select End Sub Private Sub TextBox1_Change() Dim L As Long Dim S As String Dim Found As Range If blnAuto = True Then Exit Sub S = TextBox1.Text On Error Resume Next Set Found = _ Sheet1.Range("A1:A1000").Find(What:=S & "*", _ LookIn:=xlValues, _ LookAt:=xlWhole, _ MatchCase:=False) If Found Is Nothing Then 'write on ElseIf TextBox1.SelStart = 0 Then TextBox1.Text = "" Else blnAuto = True L = Len(TextBox1.Text) TextBox1.Text = Found.Value TextBox1.SelStart = L TextBox1.SelLength = Len(TextBox1.Text) blnAuto = False End If End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Select Case KeyCode Case 8 'Backspace TextBox1.SelText = "" If TextBox1.SelStart 0 Then _ TextBox1.SelStart = TextBox1.SelStart - 1 TextBox1.SelLength = Len(TextBox1.Text) - TextBox1.SelStart Case Else End Select End Sub HTH. Best wishes Harald |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Two question on working with text | Excel Worksheet Functions | |||
Text to columns question | Excel Worksheet Functions | |||
Text to Columns Question | Excel Discussion (Misc queries) | |||
Text box question | Excel Discussion (Misc queries) | |||
Text box question | Excel Discussion (Misc queries) |