Page 1 of 1

อยากให้ label ใน userform แสดงเงื่อนไขที่เรากำหนดโดยที่ไม่ต้องคลิก

Posted: Thu Dec 13, 2018 2:42 am
by nanthaphong
ตอนนี้ label ใน User from ของผมแสดงแต่ต้องคลิกเอา อยากให้เงื่อนไขตรงกันแล้วแสดงผลเลย รบกวนด้วยครับ

Re: อยากให้ label ใน userform แสดงเงื่อนไขที่เรากำหนดโดยที่ไม่ต้องคลิก

Posted: Thu Dec 13, 2018 6:01 am
by snasui
:D กรุณาแนบตัวอย่างไฟล์ Excel กรณีเป็น VBA ให้ปฏิบัติตามกฎการใช้บอร์ดข้อ 5 ด้านบนครับ :roll:

Re: อยากให้ label ใน userform แสดงเงื่อนไขที่เรากำหนดโดยที่ไม่ต้องคลิก

Posted: Thu Dec 13, 2018 1:35 pm
by nanthaphong

Option Explicit
Dim currentRow As Long
Dim lastRow As Long

' ======================================================================================================
Private Sub cmdPreviousData_Click()
subPosition
If currentRow < 3 Then
MsgBox "Already at begining of list!"
Else
currentRow = currentRow - 1
txtFirstName.Text = Cells(currentRow, 1).Value
txtLastName.Text = Cells(currentRow, 2).Value
End If
subPosition
End Sub
' ======================================================================================================
Private Sub cmdGetNextData_Click()
subPosition
If currentRow >= lastRow Then
MsgBox "Already at end of list!"
Else
currentRow = currentRow + 1
txtFirstName.Text = Cells(currentRow, 1).Value
txtLastName.Text = Cells(currentRow, 2).Value
End If
subPosition
End Sub

Private Sub Label11_Click()
If txtFirstName.Text = "" Then
Label11 = ""

ElseIf txtLastName.Text = "" Then
Label11 = ""

ElseIf txtFirstName.Text = txtLastName.Text Then
Label11 = "OK"

Else
Label11 = "NG"
End If

End Sub

' ======================================================================================================
Private Sub cndSend_Click()
With ActiveSheet
currentRow = .Cells(.Rows.Count, "A").End(xlUp).Row
currentRow = currentRow + 1
End With
Cells(currentRow, 1).Value = txtFirstName.Text
Cells(currentRow, 2).Value = txtLastName.Text
'Cells(currentRow, 3).Value = TextBox1.Text

ขอโทษที่ครับ รบกวนด้วยนะครับ

Re: อยากให้ label ใน userform แสดงเงื่อนไขที่เรากำหนดโดยที่ไม่ต้องคลิก

Posted: Thu Dec 13, 2018 1:56 pm
by logic
โค้ดที่โพสต์มาผิดรูปแบบครับ ดูตัวอย่างที่กฎข้อ 5 ใหม่ครับ

อ่อ...ไฟล์ตัวอย่างนี่จำเป็นสำคนที่ช่วยตอบ ถ้าไม่มีแนบจะเปิดผ่านกันหมดครับ