snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
ผมสร้าง Userform มาใช้งานเวลากด Enter แล้วอยากให้มันคลุมข้อความตามรูปครับ
Capture.JPG
การทำงานคือ พิมพ์ตัวเลขใน Textbox แล้วกดปุ่ม Test บน Form
แต่ต้องการอยากให้ กด Enter ที่ คีย์บอร์ดแทนครับ
และเมื่อ Enter แล้ว Textbox พร้อมที่จะรับข้อมูลเข้าไปไหม่ คือคุมข้อความเก่าตามรูปครับ
Private Sub ChangeLabel()
If Label1 = "เปลี่ยนชื่อแล้ว" Then
GoTo pong
End If
Label1 = "เปลี่ยนชื่อแล้ว"
Label1.BackColor = &H80FF80
pong:
End Sub
Private Sub CheckChange()
Dim LResult As String
Label1 = ""
Label1.BackColor = &H8000000F
On Error GoTo pong
Range("G6").Select
Cells.Range("G6:G600").Find(What:=TextBox2, _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
TextBox3.Value = ActiveCell.Value
ActiveCell.Offset(0, -4).Select
LResult = Left(ActiveCell.Value, 7)
TextBox1.Value = LResult
Label1 = TextBox4 + "-" + TextBox1
pong:
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Call CheckChange
With Me.TextBox2
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
Private Sub ChangeLabel()
If Label1 = "เปลี่ยนชื่อแล้ว" Then
GoTo pong
End If
Label1 = "เปลี่ยนชื่อแล้ว"
Label1.BackColor = &H80FF80
pong:
End Sub
Private Sub CheckChange()
Dim LResult As String
Label1 = ""
Label1.BackColor = &H8000000F
On Error GoTo pong
Range("G6").Select
Cells.Range("G6:G600").Find(What:=TextBox2, _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
TextBox3.Value = ActiveCell.Value
ActiveCell.Offset(0, -4).Select
LResult = Left(ActiveCell.Value, 7)
TextBox1.Value = LResult
Label1 = TextBox4 + "-" + TextBox1
pong:
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Call CheckChange
With Me.TextBox2
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Me.Label1 = "กด Enter แล้ว "
With Me.TextBox2
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
You do not have the required permissions to view the files attached to this post.