返回列表 上一主題 發帖

[發問] 請教TextBox輸入錯誤如何回到原位置

回復 3# 准提部林
Cancel = True 即可取消Exit動作, 讓駐點留在原位
同理
ByVal KeyCode As MSForms.ReturnInteger
  1. Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  2.     If KeyCode = 13 And TextBox1 > "" Then
  3.         Dim Rng As Range
  4.         Dim ax As Variant
  5.         Dim bx As String
  6.         Set Rng = Sheets("data").[K1:L24]
  7.         bx = TextBox1.Text
  8.         ax = Application.VLookup(bx, Rng, 2, 0)
  9.         If Not IsError(ax) Then
  10.             Label4 = ax
  11.         Else
  12.             MsgBox "輸入錯誤"
  13.             'TextBox1 = ""
  14.             KeyCode = True
  15.             TextBox1.SelStart = 0
  16.             TextBox1.SelLength = Len(TextBox1)
  17.         End If
  18.     End If
  19. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 5# 准提部林
沒有2000可了解
  1. TextBox1.SelStart = 0
  2. TextBox1.SelLength = Len(TextBox1)
複製代碼
試試不MsgBox, 這段程式碼可用嗎?
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 君子為目標,小人為目的。
返回列表 上一主題